本文整理汇总了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))
}
示例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
}
示例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())
}
}
}
示例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
}
示例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())
}
}
}
示例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
}
示例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)
}
示例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)
}
}
示例9: checkWeiXinReturn
func checkWeiXinReturn(retData *WeiXinError) bool {
if retData.ErrCode != 0 {
log.Error(retData.ErrMsg)
return false
}
return true
}
示例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
}
示例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)
}
示例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
}
}
示例13: hostname
//获取主机名
func (s *IdGenerator) hostname() string {
name, err := os.Hostname()
if err != nil {
log.Error("获取主机名失败: %v", err)
return "default_host_"
}
return name
}
示例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
}
示例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()
}