Привет, я бы так делать не советовал. Почему не использовать обычное журналирование? Если проблема в том, что поиск нужной строки занимает вечность, у меня такое тоже бывало.
Ниже мой код 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
}