Skip to content

Commit

Permalink
数据返回为nil时处理
Browse files Browse the repository at this point in the history
  • Loading branch information
hulutech-web committed Oct 29, 2024
1 parent 33e10ca commit cf5d7bc
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions http_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func (h *HttpResult) Success(message string, data interface{}) http.Response {
if message == "" {
message = facades.Config().GetString("http_result.Message")
}
//查询的结果有可能存在data为nil的情况,判断如果是nil则,给定一个[]string{}类型的数据,避免前端页面报错
if data == nil {
data = []string{}
}
return h.Context.Response().Success().Json(http.Json{
"message": message,
"data": data,
Expand Down

0 comments on commit cf5d7bc

Please sign in to comment.