From 47b46118cd08dc966d04d4264af53d903e3294b1 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 29 Sep 2021 00:21:47 +0800 Subject: [PATCH] fix default bug --- service.go | 3 --- table/api.go | 8 +++++--- table/process.go | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) delete mode 100644 service.go diff --git a/service.go b/service.go deleted file mode 100644 index 564da7e8..00000000 --- a/service.go +++ /dev/null @@ -1,3 +0,0 @@ -package main - -// 服务设定 diff --git a/table/api.go b/table/api.go index 6d947ad3..e854ce4d 100644 --- a/table/api.go +++ b/table/api.go @@ -24,15 +24,15 @@ func (table *Table) loadAPIs() { api := defaults[name] api.Name = name - if table.APIs[name].Process == "" { + if table.APIs[name].Process != "" { api.Process = table.APIs[name].Process } - if table.APIs[name].Guard == "" { + if table.APIs[name].Guard != "" { api.Guard = table.APIs[name].Guard } - if table.APIs[name].Default == nil { + if table.APIs[name].Default != nil { api.Default = table.APIs[name].Default } defaults[name] = api @@ -137,12 +137,14 @@ func (api API) IsGuard(v interface{}) bool { if !ok { return false } + guards := strings.Split(api.Guard, ",") for _, guard := range guards { guard = strings.TrimSpace(guard) handler, has := gou.HTTPGuards[guard] if has { handler(c) + fmt.Println(api.Guard, c.IsAborted()) return c.IsAborted() } } diff --git a/table/process.go b/table/process.go index 8ec076ff..c4c7e3f1 100644 --- a/table/process.go +++ b/table/process.go @@ -62,9 +62,9 @@ func ProcessSearch(process *gou.Process) interface{} { // 合并默认查询参数 func mergeQueryParam(param gou.QueryParam, api API, i int) gou.QueryParam { if len(api.Default) > i && api.Default[i] != nil { - defaults, ok := api.Default[i].(gou.QueryParam) + defaults, ok := gou.AnyToQueryParam(api.Default[i]) if !ok { - exception.New("参数默认值数据结构错误", 400).Throw() + exception.New("参数默认值数据结构错误", 400).Ctx(api.Default[i]).Throw() } if defaults.Withs != nil { param.Withs = defaults.Withs