Skip to content

Commit

Permalink
添加事例
Browse files Browse the repository at this point in the history
  • Loading branch information
hulutech-web committed Dec 5, 2024
1 parent 20dfb4a commit 9941a51
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
11 changes: 2 additions & 9 deletions http_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,9 @@ func (h *HttpResult) Success(message string, data interface{}) http.Response {
if message == "" {
message = facades.Config().GetString("http_result.Message")
}

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{}类型的数据,避免前端页面报错
//或者判断data的slice类型的长度为0
res := []string{}
if data == nil {
return h.Context.Response().Success().Json(http.Json{
"message": message,
Expand Down
1 change: 1 addition & 0 deletions paginator.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (h *HttpResult) SearchByIncludes(column string, values []any) *HttpResult {
}

// SearchByParams
// example SearchByParams(map[string]{}{"name":"user"}, map[string]interface{}{"state",1}, []string{"age"}...)
// ?name=xxx&pageSize=1&currentPage=1&sort=xxx&order=xxx
func (h *HttpResult) SearchByParams(params map[string]string, conditionMap map[string]interface{}, excepts ...string) *HttpResult {
for _, except := range excepts {
Expand Down

0 comments on commit 9941a51

Please sign in to comment.