From 68c5453758e8f788b02a51a7e9d896bc702e55a9 Mon Sep 17 00:00:00 2001 From: hulutech-web Date: Tue, 29 Oct 2024 10:10:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BF=94=E5=9B=9E=E7=BB=93?= =?UTF-8?q?=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- http_result.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/http_result.go b/http_result.go index 9dc0368..f122926 100644 --- a/http_result.go +++ b/http_result.go @@ -42,9 +42,22 @@ func (h *HttpResult) Success(message string, data interface{}) http.Response { message = facades.Config().GetString("http_result.Message") } //查询的结果有可能存在data为nil的情况,判断如果是nil则,给定一个[]string{}类型的数据,避免前端页面报错 + //或者判断data的slice类型的长度为0 + res := []string{} if data == nil { - data = []string{} + return h.Context.Response().Success().Json(http.Json{ + "message": message, + "data": res, + }) } + slice, ok := data.([]interface{}) + if ok && len(slice) == 0 { + return h.Context.Response().Success().Json(http.Json{ + "message": message, + "data": res, + }) + } + return h.Context.Response().Success().Json(http.Json{ "message": message, "data": data,