diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index baf39e0..7fb52bc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,5 +9,14 @@ jobs: simple-test: runs-on: ubuntu-latest steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.18 + cache: true + - name: test run: cd test && go test -short diff --git a/action/hook.go b/action/hook.go index 4f8308d..a7d64c5 100644 --- a/action/hook.go +++ b/action/hook.go @@ -20,6 +20,8 @@ type Hook struct { AfterExecutorDo func(ctx context.Context, n *Node, method string) error } +// todo hook可获取到executor的返回值 + var hooksMap = map[string][]Hook{} func RegHook(h Hook) { diff --git a/config/executor/action.go b/config/executor/action.go index 51ff084..7d5d763 100644 --- a/config/executor/action.go +++ b/config/executor/action.go @@ -12,6 +12,7 @@ type ActionExecutor interface { Delete(ctx context.Context, table string, where model.Map) (count int64, err error) } +// todo 调整executor var actionExecutorMap = map[string]ActionExecutor{} func RegActionExecutor(name string, e ActionExecutor) { diff --git a/config/functions.go b/config/functions.go index 16ce7ab..81a7c98 100644 --- a/config/functions.go +++ b/config/functions.go @@ -7,8 +7,16 @@ import ( "github.com/gogf/gf/v2/frame/g" ) +type ParamItem struct { + Type string + Name string + Desc string +} + +// todo Func会和下方functions混淆,不利于代码补全 type Func struct { - Handler func(ctx context.Context, param model.Map) (res any, err error) + ParamList []ParamItem + Handler func(ctx context.Context, param model.Map) (res any, err error) } type Functions struct { @@ -22,15 +30,6 @@ func (f *Functions) Bind(name string, _func Func) { f.funcMap[name] = _func } -func (f *Functions) BindHandlerFunc(name string, handler func(ctx context.Context, param model.Map) (res any, err error)) { - if _, exists := f.funcMap[name]; exists { - panic(fmt.Errorf(" function %s has exists", name)) - } - f.funcMap[name] = struct { - Handler func(ctx context.Context, param model.Map) (res any, err error) - }{Handler: handler} -} - func (f *Functions) Call(ctx context.Context, name string, param g.Map) (any, error) { return f.funcMap[name].Handler(ctx, param) } diff --git a/consts/node.go b/consts/node.go index 5c9a1b8..75f1fc4 100644 --- a/consts/node.go +++ b/consts/node.go @@ -15,7 +15,7 @@ const ( const ( Role = "@role" Page = "page" // page num - Count = "count" // page size + Count = "count" // page size // todo access中增加限制count,防止被恶意下载数据 Query = "query" ) diff --git a/test/z_app_test.go b/test/z_app_test.go index d4e204c..9cc1875 100644 --- a/test/z_app_test.go +++ b/test/z_app_test.go @@ -58,11 +58,11 @@ func App(ctx context.Context, a *apijson.ApiJson) { panic(err) } - a.Config().Functions.Bind("test", struct { - Handler func(ctx context.Context, param model.Map) (res any, err error) - }{Handler: func(ctx context.Context, param model.Map) (res any, err error) { - return "nihao", nil - }}) + a.Config().Functions.Bind("test", config.Func{ + Handler: func(ctx context.Context, param model.Map) (res any, err error) { + return "你好", nil + }, + }) a.Config().AccessListProvider = "custom"