你好,我不建议这样做。为什么不用普通的日志记录呢?如果问题是定位行号要找很久,那我也遇到过。
下面是我的 http 错误响应代码,不过用类似的方法也能立刻定位失败原因。
type FailureReply struct {
Detail string `json:"detail"` // My own explanaton of why this happened.
Error string `json:"error"`
}
permissions, lookupErr := service.Queries.GetPurePermissionsByUserId(context.Background(), member.ID)
if lookupErr != nil {
helpers.RespondWithJSON(writer, helpers.FailureReply{
Detail: "Could not retrieve member permissions",
Error: lookupErr.Error(),
})
return
}
从英语翻译·查看原文Hi, this isn't something I'd advise. Why aren't you using ordinary logging? If locating the line takes you ages and that is the difficulty, I've run into that too.
Here's my http error response code, though a similar approach lets you immediately locate whatever caused the failure.
type FailureReply struct {
Detail string `json:"detail"` // My own explanaton of why this happened.
Error string `json:"error"`
}
permissions, lookupErr := service.Queries.GetPurePermissionsByUserId(context.Background(), member.ID)
if lookupErr != nil {
helpers.RespondWithJSON(writer, helpers.FailureReply{
Detail: "Could not retrieve member permissions",
Error: lookupErr.Error(),
})
return
}