Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf403a04

Browse files
committed
feat: add functions param
1 parentff2aa50 commitf403a04

File tree

6 files changed

+27
-16
lines changed

6 files changed

+27
-16
lines changed

‎.github/workflows/test.yml

Lines changed: 9 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ type Hook struct {
2020
AfterExecutorDofunc(ctx context.Context,n*Node,methodstring)error
2121
}
2222

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

2527
funcRegHook(hHook) {

‎config/executor/action.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type ActionExecutor interface {
1212
Delete(ctx context.Context,tablestring,where model.Map) (countint64,errerror)
1313
}
1414

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

1718
funcRegActionExecutor(namestring,eActionExecutor) {

‎config/functions.go

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

10+
typeParamItemstruct {
11+
Typestring
12+
Namestring
13+
Descstring
14+
}
15+
16+
// todo Func会和下方functions混淆,不利于代码补全
1017
typeFuncstruct {
11-
Handlerfunc(ctx context.Context,param model.Map) (resany,errerror)
18+
ParamList []ParamItem
19+
Handlerfunc(ctx context.Context,param model.Map) (resany,errerror)
1220
}
1321

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

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

‎consts/node.go

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 5 deletions
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-
Handlerfunc(ctx context.Context,param model.Map) (resany,errerror)
63-
}{Handler:func(ctx context.Context,param model.Map) (resany,errerror) {
64-
return"nihao",nil
65-
}})
61+
a.Config().Functions.Bind("test",config.Func{
62+
Handler:func(ctx context.Context,param model.Map) (resany,errerror) {
63+
return"你好",nil
64+
},
65+
})
6666

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp