Skip to content

Commit

Permalink
处理interface类型
Browse files Browse the repository at this point in the history
  • Loading branch information
hulutech-web committed Dec 3, 2024
1 parent f94ac02 commit 0816490
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions http_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,16 @@ func (h *HttpResult) Success(message string, data interface{}) http.Response {
if message == "" {
message = facades.Config().GetString("http_result.Message")
}
//查询的结果有可能存在data为nil的情况,判断如果是nil则,给定一个[]string{}类型的数据,避免前端页面报错
//或者判断data的slice类型的长度为0

res := []string{}
//如果data就是一个interface{}类型,则直接返回
if _, ok := data.(interface{}); ok {
return h.Context.Response().Success().Json(http.Json{
"message": message,
"data": res,
})
}
//查询的结果有可能存在data为nil的情况,判断如果是nil则,给定一个[]string{}类型的数据,避免前端页面报错
if data == nil {
return h.Context.Response().Success().Json(http.Json{
"message": message,
Expand Down

0 comments on commit 0816490

Please sign in to comment.