• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang log.Error函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/playnb/mustang/log.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: parseRecvWeiXinMsg

//解析微信服务器转发的用户消息
func parseRecvWeiXinMsg(content []byte) *RecvWeiXinMsg {
	msg := new(RecvWeiXinMsg)
	err := xml.Unmarshal(content, msg)
	if err != nil {
		log.Error(err.Error())
		return nil
	}
	return msg
}
开发者ID:playnb,项目名称:mustang,代码行数:10,代码来源:weixin.go


示例17: Run

func (a *WSAgent) Run() {

	a.Trace("run...")
	msgChan := make(chan []byte, 1024)
	a.innerMsgChan = make(chan []byte, 1024)
	a.needClose = make(chan bool)

	go func() {
		defer utils.PrintPanicStack()
		for {
			if a.conn == nil {
				a.Error("WSAgent 连接为nil")
				a.needClose <- true
				return
			}
			data, err := a.conn.ReadMsg()
			if err != nil {
				a.Debug("读取消息错误: %v", err)
				a.needClose <- true
				return
			}

			msgChan <- data
		}
	}()

	for {
		var data []byte
		var err error
		select {
		case data = <-msgChan:
		case data = <-a.innerMsgChan:
		case <-a.needClose:
			{
				log.Error("WSAgent 发生错误")
				a.Close()
				return
			}
		}
		if a.handlerMessage != nil {
			_, err = a.handlerMessage(a, data, a.UserData)
			if err != nil {
				a.Debug("[handlerMessage]protobuf handle msg error %v", err)
				//WHY: 解析错误需要跳出循环吗?
				//break
			}
		} else if a.protobufProcessor != nil {
			_, err = a.protobufProcessor.Handler(a, data, a.UserData)
			if err != nil {
				a.Debug("[protobufProcessor]protobuf handle msg error %v", err)
				//WHY: 解析错误需要跳出循环吗?
				//break
			}
		}
	}
}
开发者ID:playnb,项目名称:mustang,代码行数:56,代码来源:websocket_agent.go


示例18: Save

func (token *WeiXinJsApiTicket) Save() {
	var err error
	if sqldb.Ormer.QueryTable(token).Filter("AppID", token.AppID).Exist() {
		_, err = sqldb.Ormer.Update(token)
	} else {
		_, err = sqldb.Ormer.Insert(token)
	}
	if err != nil {
		log.Error(err.Error())
	} else {
		log.Trace("保存微信AccessToken")
	}
}
开发者ID:playnb,项目名称:mustang,代码行数:13,代码来源:models.go


示例19: NextIds

func (id *IdGenerator) NextIds(num int) ([]uint64, error) {
	if num > maxNextIdsNum || num < 0 {
		log.Error("批量生成ID太多了,范围[0, %d]", maxNextIdsNum)
		return nil, errors.New(fmt.Sprintf("NextIds num: %d error", num))
	}
	ids := make([]uint64, num)
	id.mutex.Lock()
	defer id.mutex.Unlock()
	var err error
	for i := 0; i < num; i++ {
		ids[i], err = id.nextId()
		if err != nil {
			return nil, errors.New(fmt.Sprintf("产生单个ID失败,%s,批量生成ID数%d", err.Error(), num))
		}
	}
	return ids, nil
}
开发者ID:playnb,项目名称:mustang,代码行数:17,代码来源:snowflake.go


示例20: nextId

func (id *IdGenerator) nextId() (uint64, error) {
	timestamp := timeGen()
	if timestamp < id.lastTimestamp {
		log.Error("IdGenerator分配ID错误,检测到时光倒流 %d 微秒", id.lastTimestamp-timestamp)
		return 0, errors.New(fmt.Sprintf("IdGenerator分配ID错误,检测到时光倒流 %d 微秒", id.lastTimestamp-timestamp))
	}
	if id.lastTimestamp == timestamp {
		id.sequence = (id.sequence + 1) & sequenceMask
		if id.sequence == 0 {
			timestamp = tilNextMillis(id.lastTimestamp)
		}
	} else {
		id.sequence = 0
	}
	id.lastTimestamp = timestamp
	return uint64(((timestamp - id.twepoch) << timestampLeftShift) | (id.catalogId << catalogIdShift) | (id.workerId << workerIdShift) | id.sequence), nil
}
开发者ID:playnb,项目名称:mustang,代码行数:17,代码来源:snowflake.go



注:本文中的github.com/playnb/mustang/log.Error函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang log.Trace函数代码示例发布时间:2022-05-28
下一篇:
Golang di.DI类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap