Skip to content

Commit f403a04

Browse files
committed
feat: add functions param
1 parent ff2aa50 commit f403a04

File tree

6 files changed

+27
-16
lines changed

6 files changed

+27
-16
lines changed

.github/workflows/test.yml

+9
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,14 @@ jobs:
99
simple-test:
1010
runs-on: ubuntu-latest
1111
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v3
17+
with:
18+
go-version: 1.18
19+
cache: true
20+
1221
- name: test
1322
run: cd test && go test -short

action/hook.go

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ type Hook struct {
2020
AfterExecutorDo func(ctx context.Context, n *Node, method string) error
2121
}
2222

23+
// todo hook可获取到executor的返回值
24+
2325
var hooksMap = map[string][]Hook{}
2426

2527
func RegHook(h Hook) {

config/executor/action.go

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type ActionExecutor interface {
1212
Delete(ctx context.Context, table string, where model.Map) (count int64, err error)
1313
}
1414

15+
// todo 调整executor
1516
var actionExecutorMap = map[string]ActionExecutor{}
1617

1718
func RegActionExecutor(name string, e ActionExecutor) {

config/functions.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@ import (
77
"github.com/gogf/gf/v2/frame/g"
88
)
99

10+
type ParamItem struct {
11+
Type string
12+
Name string
13+
Desc string
14+
}
15+
16+
// todo Func会和下方functions混淆,不利于代码补全
1017
type Func struct {
11-
Handler func(ctx context.Context, param model.Map) (res any, err error)
18+
ParamList []ParamItem
19+
Handler func(ctx context.Context, param model.Map) (res any, err error)
1220
}
1321

1422
type Functions struct {
@@ -22,15 +30,6 @@ func (f *Functions) Bind(name string, _func Func) {
2230
f.funcMap[name] = _func
2331
}
2432

25-
func (f *Functions) BindHandlerFunc(name string, handler func(ctx context.Context, param model.Map) (res any, err error)) {
26-
if _, exists := f.funcMap[name]; exists {
27-
panic(fmt.Errorf(" function %s has exists", name))
28-
}
29-
f.funcMap[name] = struct {
30-
Handler func(ctx context.Context, param model.Map) (res any, err error)
31-
}{Handler: handler}
32-
}
33-
3433
func (f *Functions) Call(ctx context.Context, name string, param g.Map) (any, error) {
3534
return f.funcMap[name].Handler(ctx, param)
3635
}

consts/node.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const (
1515
const (
1616
Role = "@role"
1717
Page = "page" // page num
18-
Count = "count" // page size
18+
Count = "count" // page size // todo access中增加限制count,防止被恶意下载数据
1919
Query = "query"
2020
)
2121

test/z_app_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ func App(ctx context.Context, a *apijson.ApiJson) {
5858
panic(err)
5959
}
6060

61-
a.Config().Functions.Bind("test", struct {
62-
Handler func(ctx context.Context, param model.Map) (res any, err error)
63-
}{Handler: func(ctx context.Context, param model.Map) (res any, err error) {
64-
return "nihao", nil
65-
}})
61+
a.Config().Functions.Bind("test", config.Func{
62+
Handler: func(ctx context.Context, param model.Map) (res any, err error) {
63+
return "你好", nil
64+
},
65+
})
6666

6767
a.Config().AccessListProvider = "custom"
6868

0 commit comments

Comments
 (0)