本文整理匯總了Golang中github.com/hailocab/platform-layer/errors.Error.Error方法的典型用法代碼示例。如果您正苦於以下問題:Golang Error.Error方法的具體用法?Golang Error.Error怎麽用?Golang Error.Error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hailocab/platform-layer/errors.Error
的用法示例。
在下文中一共展示了Error.Error方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: publishError
// publishError publishes an event when a handler returns an error
func publishError(req *Request, e errors.Error) {
if !PublishErrors {
return
}
stacktrace := ""
if e.MultiStack() != nil {
stacktrace = e.MultiStack().String()
}
application := ""
if req.Auth().IsAuth() && req.Auth().AuthUser() != nil {
application = req.Auth().AuthUser().Application()
}
userId := ""
if req.Auth().IsAuth() && req.Auth().AuthUser() != nil {
userId = req.Auth().AuthUser().Id
}
msg := map[string]interface{}{
"created": time.Now(),
"service": Name,
"version": Version,
"azName": az,
"hostname": hostname,
"instanceId": InstanceID,
"error": e.Error(),
"type": e.Type(),
"code": e.Code(),
"description": e.Description(),
"httpCode": e.HttpCode(),
"context": e.Context(),
"userId": userId,
"application": application,
"traceId": req.TraceID(),
"stacktrace": stacktrace,
}
payload, err := json.Marshal(msg)
if err != nil {
log.Errorf("[Server] Failed to JSON encode error event: %v", err)
}
if err = nsq.Publish(errorTopic, payload); err != nil {
log.Errorf("[Server] Failed to publish error event: %v", err)
}
}