Golang encoding/json marshall add null



嗨,我正在使用golang进行编码/json,它返回带有null的json错误:

{"user_message":"Can't find any Query with those parameters","application_context":"GroupsRepository.GetGroupsByQuery: ApplicationError: UserMessage - Error querying database for many Groups. ApplicationContext - Groups.GetMany: pq: column "refill_too_soon_gpi_digits" does not exist"} null

我的方式是:

func EncodeErrorResponse(w http.ResponseWriter, err error, status int) {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(err)
}

有人可以帮我吗?

查看您引用的 JSON 输出,看起来错误编码正确,但在 JSON 之后输出 null,表示单独的写入操作。调用 EncodeErrorResponse 的函数在调用它之后,正在将其他输出写入 ResponseWriter。

相关内容

最新更新