当前位置: 首页>>代码示例>>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;未经允许,请勿转载。