當前位置: 首頁>>代碼示例>>Golang>>正文


Golang log.Error函數代碼示例

本文整理匯總了Golang中github.com/playnb/mustang/log.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: clientCall

func clientCall(min int32) {
	startTime := currentTimeMillis()
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	transport, err := thrift.NewTSocket(NetworkAddr)
	for err != nil {
		transport, err = thrift.NewTSocket(NetworkAddr)
		if err != nil {
			log.Error("error resolving address:", err)
		}
		time.Sleep(1 * time.Second)
	}

	useTransport := transportFactory.GetTransport(transport)
	client := demo.NewRpcServiceClientFactory(useTransport, protocolFactory)
	if err := transport.Open(); err != nil {
		log.Error("Error opening socket to 127.0.0.1:19090", " ", err)
		return
	}
	defer transport.Close()

	for i := min; i < min+3; i++ {
		r1, e1 := client.Add(i, i+1)
		log.Trace("%d %s %v %v", i, "Call->", r1, e1)
	}

	endTime := currentTimeMillis()
	log.Trace("Program exit. time->", endTime, startTime, (endTime - startTime))
}
開發者ID:playnb,項目名稱:grasslands,代碼行數:30,代碼來源:test_thrift.go

示例2: LoadJsonFile

func LoadJsonFile(fileName string, conf interface{}) bool {
	//confName := ""
	if !strings.HasSuffix(fileName, ".json") {
		fileName = fileName + ".json"
		//confName = fileName
	} else {
		//confName = fileName[:len(fileName)-len(".json")]
	}
	r, err := os.Open(fileName)
	if err != nil {
		log.Error(err.Error())
		return false
	}
	buf := make([]byte, 1024*1024)
	n, err := r.Read(buf)
	if err != nil {
		log.Error(err.Error())
		return false
	}
	str := string(buf[:n])
	//str = strings.Replace(str, "//", "######", -1)
	//str = strings.Replace(str, "/", "\\/", -1)
	//str = strings.Replace(str, "######", "//", -1)
	err = json.Unmarshal([]byte(str), conf)
	//decoder := json.NewDecoder(r)
	//err = decoder.Decode(conf)
	if err != nil {
		log.Error(err.Error())
		return false
	}
	return true
}
開發者ID:playnb,項目名稱:mustang,代碼行數:32,代碼來源:conf.go

示例3: RefreshAccessToken

//獲取微信服務器的Token
func RefreshAccessToken(loop bool) {
	type wxJsonToken struct {
		WeiXinError
		AccessToken string `json:"access_token"`
		ExpiresIn   int    `json:"expires_in"`
	}

	wxToken := new(WeiXinAccessToken)
	if !wxToken.Load(wxProfile.AppID) {
		wxToken.ExpireIn = 0
		wxProfile.AccessToken = ""
	} else {
		wxProfile.AccessToken = wxToken.AccessToken
		log.Trace("加載數據庫微信Accesstoken: %s", wxProfile.AccessToken)
	}

	for loop {
		newSec := time.Now().UnixNano() / time.Second.Nanoseconds()
		for newSec < wxToken.ExpireIn {
			time.Sleep(time.Second)
			newSec = time.Now().UnixNano() / time.Second.Nanoseconds()
		}
		wxProfile.AccessToken = ""
		log.Trace("微信Accesstoken過期,重新獲取Token")
		url := "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET"
		url = strings.Replace(url, "APPID", wxProfile.AppID, -1)
		url = strings.Replace(url, "APPSECRET", wxProfile.AppSecret, -1)
		//log.Debug(url)
		res, err := http.Get(url)
		if err != nil {
			log.Error("獲取Token失敗 %v", err)
		}
		result, err := ioutil.ReadAll(res.Body)
		res.Body.Close()
		if err != nil {
			log.Error("解析Token失敗 %v", err)
		}
		log.Debug(string(result))
		var jsonData wxJsonToken
		if err := json.Unmarshal(result, &jsonData); err == nil {
			wxProfile.AccessToken = jsonData.AccessToken
			log.Trace("收到Token: %s", wxProfile.AccessToken)

			wxToken.AccessToken = jsonData.AccessToken
			wxToken.ExpireIn = newSec + int64(jsonData.ExpiresIn) - 60*10
			wxToken.Save()
		} else {
			log.Error(err.Error())
		}
	}
}
開發者ID:playnb,項目名稱:mustang,代碼行數:52,代碼來源:accestoken.go

示例4: Load

func (token *WeiXinJsApiTicket) Load(appID string) bool {
	token.AppID = appID
	err := sqldb.Ormer.Read(token)
	if err == nil {
		return true
	} else if err == orm.ErrNoRows {
		log.Error("查詢不到")
		return false
	} else if err == orm.ErrMissPK {
		log.Error("找不到主鍵")
		return false
	}
	return false
}
開發者ID:playnb,項目名稱:mustang,代碼行數:14,代碼來源:models.go

示例5: RefreshJsApiTicket

//刷新JsApiTicket
func RefreshJsApiTicket(loop bool) {
	type wxJsonToken struct {
		WeiXinError
		JsApiTicket string `json:"ticket"`
		ExpiresIn   int    `json:"expires_in"`
	}

	wxTicket := new(WeiXinJsApiTicket)
	if !wxTicket.Load(wxProfile.AppID) {
		wxTicket.ExpireIn = 0
	} else {
		wxProfile.JsApiTicket = wxTicket.JsApiTicket
		log.Trace("加載數據庫微信JsApiTicket: %s", wxProfile.JsApiTicket)
	}

	for loop {
		newSec := time.Now().UnixNano() / time.Second.Nanoseconds()
		for newSec < wxTicket.ExpireIn || len(wxProfile.AccessToken) == 0 {
			time.Sleep(time.Second)
			newSec = time.Now().UnixNano() / time.Second.Nanoseconds()
		}
		log.Trace("微信JsApiTicket過期,重新獲取JsApiTicket")
		url := "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi"
		url = strings.Replace(url, "ACCESS_TOKEN", wxProfile.AccessToken, -1)
		//log.Debug(url)
		res, err := http.Get(url)
		if err != nil {
			log.Error("獲取JsApiTicket失敗 %v", err)
		}
		result, err := ioutil.ReadAll(res.Body)
		res.Body.Close()
		if err != nil {
			log.Error("解析JsApiTicket失敗 %v", err)
		}
		log.Debug(string(result))
		var jsonData wxJsonToken
		if err := json.Unmarshal(result, &jsonData); err == nil {
			wxProfile.JsApiTicket = wxTicket.JsApiTicket
			log.Trace("收到JsApiTicket: %s", wxProfile.AccessToken)

			wxTicket.JsApiTicket = jsonData.JsApiTicket
			wxTicket.ExpireIn = newSec + int64(jsonData.ExpiresIn) - 60*10
			wxTicket.Save()
		} else {
			log.Error(err.Error())
		}
	}
}
開發者ID:playnb,項目名稱:mustang,代碼行數:49,代碼來源:accestoken.go

示例6: LoadJsonURL

func LoadJsonURL(url string, conf interface{}) bool {

	resp, err := http.Get(url)
	if err != nil {
		panic(err.Error())
	}

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		panic(err.Error())
	}

	//str = strings.Replace(str, "//", "######", -1)
	//str = strings.Replace(str, "/", "\\/", -1)
	//str = strings.Replace(str, "######", "//", -1)
	err = json.Unmarshal(body, conf)
	//decoder := json.NewDecoder(r)
	//err = decoder.Decode(conf)
	if err != nil {
		log.Error(err.Error())
		return false
	}
	return true
}
開發者ID:playnb,項目名稱:mustang,代碼行數:25,代碼來源:conf.go

示例7: getCurrentDirectory

func getCurrentDirectory() string {
	dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
	if err != nil {
		log.Error(err.Error())
	}
	return strings.Replace(dir, "\\", "/", -1)
}
開發者ID:playnb,項目名稱:grasslands,代碼行數:7,代碼來源:Main.go

示例8: handleStatic

func handleStatic(w http.ResponseWriter, r *http.Request) {
	path := r.URL.Path
	index := strings.LastIndex(path, ".")
	if index != -1 {
		request_type := path[index:]
		switch request_type {
		case ".css":
			w.Header().Set("content-type", "text/css")
		case ".js":
			w.Header().Set("content-type", "text/javascript")
		default:
		}
	}
	path = baseDir + path
	log.Trace("獲取靜態文件: %s", path)
	fin, err := os.Open(path)
	defer fin.Close()
	if err != nil {
		log.Error("static resource: %v", err)
		w.WriteHeader(505)
	} else {
		fd, _ := ioutil.ReadAll(fin)
		w.Write(fd)
	}
}
開發者ID:playnb,項目名稱:grasslands,代碼行數:25,代碼來源:Main.go

示例9: checkWeiXinReturn

func checkWeiXinReturn(retData *WeiXinError) bool {
	if retData.ErrCode != 0 {
		log.Error(retData.ErrMsg)
		return false
	}
	return true
}
開發者ID:playnb,項目名稱:mustang,代碼行數:7,代碼來源:weixin.go

示例10: newWSConn

func newWSConn(conn *websocket.Conn, pendingWriteNum int) *WSConn {
	wsConn := new(WSConn)
	wsConn.conn = conn
	wsConn.writeChan = make(chan []byte, pendingWriteNum)

	go func() {
		for b := range wsConn.writeChan {
			if b == nil {
				break
			}

			err := conn.WriteMessage(websocket.BinaryMessage, b)
			if err != nil {
				log.Error(err.Error())
				break
			}
		}

		conn.Close()
		wsConn.Lock()
		wsConn.closeFlag = true
		wsConn.Unlock()
	}()

	return wsConn
}
開發者ID:playnb,項目名稱:mustang,代碼行數:26,代碼來源:websocket_conn.go

示例11: StartService

func (g *gateService) StartService(superRpcAddr string) {
	superClient, err := msg.DialSuperService("tcp", superRpcAddr)
	maxRetry := 10
	for err != nil {
		if maxRetry > 0 {
			maxRetry = maxRetry - 1
		} else {
			log.Fatal("連接SuperService失敗")
			return
		}
		log.Error("連接SuperService失敗,1秒後重試 :%v", err)
		time.Sleep(time.Second * 1)
		superClient, err = msg.DialSuperService("tcp", superRpcAddr)
	}
	res, err := superClient.Login(&msg.LoginRequst{ServiceIp: proto.String("127.0.0.1")})
	if err != nil {
		log.Fatal("[GATE] 登錄SuperService失敗 rpc:%s", superRpcAddr)
		return
	}
	g.SuperClient = superClient
	g.gateway.Addr = string(res.GetServiceIp()) + ":" + strconv.Itoa(int(res.GetExterPort()))
	g.gateway.HTTPTimeout = 3 * 60
	g.gateway.MaxConnNum = 1000
	g.gateway.PendingWriteNum = 1000
	g.gateway.ProtobufProcessor = g.processor
	log.Trace("[GATE] 網關服務在%s:%d 啟動", string(res.GetServiceIp()), res.GetExterPort())
	g.gateway.Run(utils.CloseSig)
}
開發者ID:playnb,項目名稱:grasslands,代碼行數:28,代碼來源:gate.go

示例12: RegistAuthRedirectUrl

//注冊處理redirecturl
func RegistAuthRedirectUrl(state string, redirect string) {
	url, ok := wxProfile.authRedirectAppUrl[state]
	if ok == true {
		log.Error(" 重複注冊APP:%s的authRedirectAppUrl:%s (已經存在%s)", state, redirect, url)
	} else {
		wxProfile.authRedirectAppUrl[state] = redirect
	}
}
開發者ID:playnb,項目名稱:mustang,代碼行數:9,代碼來源:weixin.go

示例13: hostname

//獲取主機名
func (s *IdGenerator) hostname() string {
	name, err := os.Hostname()
	if err != nil {
		log.Error("獲取主機名失敗: %v", err)
		return "default_host_"
	}
	return name
}
開發者ID:playnb,項目名稱:mustang,代碼行數:9,代碼來源:snowflake.go

示例14: NewIdGenerator

//構造一個新的id分配器
func NewIdGenerator(workerId, catalogId int64) (*IdGenerator, error) {
	if workerId > maxWorkerId || workerId < 0 {
		log.Error("workerId溢出,取值範圍[0, %d]", maxWorkerId)
		return nil, errors.New(fmt.Sprintf("worker Id: %d error", workerId))
	}
	if catalogId > maxCatalogId || catalogId < 0 {
		log.Error("catalogId溢出,取值範圍[0, %d]", maxCatalogId)
		return nil, errors.New(fmt.Sprintf("catalog Id: %d error", catalogId))
	}
	gid := makeGenID(workerId, catalogId)
	id, ok := generators[gid]
	if !ok {
		id = makeIdGenerator(workerId, catalogId)
		generators[gid] = id
	}
	return id, nil
}
開發者ID:playnb,項目名稱:mustang,代碼行數:18,代碼來源:snowflake.go

示例15: TestProtorpc

func TestProtorpc() {
	go startProtorpcService()

	echoClient, err := Msg.DialEchoService("tcp", NetworkAddr)
	for err != nil {
		log.Error("連接服務失敗 :%v", err)
		time.Sleep(time.Second * 1)
		echoClient, err = Msg.DialEchoService("tcp", NetworkAddr)
	}
	echoClient, err = Msg.DialEchoService("tcp", NetworkAddr)

	wg := new(sync.WaitGroup)

	for i := 0; i < 10; i++ {
		wg.Add(1)
		go func(i int) {
			defer wg.Done()
			log.Debug("RPC Call Begin..." + strconv.Itoa(i))
			reply, err := echoClient.Echo(&Msg.EchoRequest{Msg: proto.String("Hello!" + strconv.Itoa(i))})
			if err != nil {
				log.Error("EchoTwice: %v", err)
			}
			log.Trace(reply.GetMsg())
			log.Debug("RPC Call Finish..." + strconv.Itoa(i))
		}(i)
	}
	/*
		client, err := protorpc.Dial("tcp", `127.0.0.1:9527`)
		if err != nil {
			log.Fatal("protorpc.Dial: %v", err)
		}
		defer client.Close()

		echoClient1 := &Msg.EchoServiceClient{client}
		echoClient2 := &Msg.EchoServiceClient{client}
		reply, err = echoClient1.Echo(args)
		log.Trace(reply.GetMsg())
		reply, err = echoClient2.EchoTwice(args)
		log.Trace(reply.GetMsg())
		_, _ = reply, err
	*/

	wg.Wait()
	echoClient.Close()
}
開發者ID:playnb,項目名稱:grasslands,代碼行數:45,代碼來源:test_protorpc.go


注:本文中的github.com/playnb/mustang/log.Error函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。