本文整理汇总了Golang中github.com/hailocab/platform-layer/errors.Error.Description方法的典型用法代码示例。如果您正苦于以下问题:Golang Error.Description方法的具体用法?Golang Error.Description怎么用?Golang Error.Description使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/hailocab/platform-layer/errors.Error
的用法示例。
在下文中一共展示了Error.Description方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
}
示例2: traceRsp
// traceRsp decides if we want to trigger a trace event (when processing response) and if so deals with it
func (c *client) traceRsp(req *Request, rsp *Response, err errors.Error, d time.Duration) {
if req.shouldTrace() {
e := &traceproto.Event{
Timestamp: proto.Int64(time.Now().UnixNano()),
TraceId: proto.String(req.TraceID()),
Type: traceproto.Event_REP.Enum(),
MessageId: proto.String(req.MessageID()),
From: proto.String(req.From()),
FromEndpoint: proto.String(req.FromEndpoint()),
To: proto.String(fmt.Sprintf("%v.%v", req.Service(), req.Endpoint())),
ParentMessageId: proto.String(req.ParentMessageID()),
Hostname: proto.String(c.hostname),
Az: proto.String(c.az),
Payload: proto.String(""), // @todo
Duration: proto.Int64(int64(d)),
PersistentTrace: proto.Bool(req.TraceShouldPersist()),
}
if err != nil {
e.ErrorCode = proto.String(err.Code())
e.ErrorDescription = proto.String(err.Description())
}
trace.Send(e)
}
}
示例3: traceOut
// traceOut traces a request outbound from a service handler
func traceOut(req *Request, msg proto.Message, err errors.Error, d time.Duration) {
if req.shouldTrace() {
e := &traceproto.Event{
Timestamp: proto.Int64(time.Now().UnixNano()),
TraceId: proto.String(req.TraceID()),
Type: traceproto.Event_OUT.Enum(),
MessageId: proto.String(req.MessageID()),
ParentMessageId: proto.String(req.ParentMessageID()),
From: proto.String(req.From()),
To: proto.String(fmt.Sprintf("%v.%v", req.Service(), req.Endpoint())),
Hostname: proto.String(hostname),
Az: proto.String(az),
Payload: proto.String(""), // @todo
HandlerInstanceId: proto.String(InstanceID),
Duration: proto.Int64(int64(d)),
PersistentTrace: proto.Bool(req.TraceShouldPersist()),
}
if err != nil {
e.ErrorCode = proto.String(err.Code())
e.ErrorDescription = proto.String(err.Description())
}
trace.Send(e)
}
}