@@ -2,8 +2,9 @@ package action
22
33import (
44 "context"
5- "github.com/glennliao/apijson-go/config/db "
5+ "github.com/glennliao/apijson-go/config"
66 "github.com/glennliao/apijson-go/consts"
7+ "github.com/glennliao/apijson-go/model"
78 "github.com/gogf/gf/v2/database/gdb"
89 "github.com/gogf/gf/v2/errors/gerror"
910 "github.com/gogf/gf/v2/frame/g"
@@ -14,20 +15,36 @@ import (
1415// Action 非get查询的request表中的请求
1516type Action struct {
1617 ctx context.Context
17- tagRequest * db .Request
18+ tagRequest * config .Request
1819 method string
1920
20- req g .Map
21+ req model .Map
2122
2223 err error
2324
2425 children map [string ]* Node
2526 keyNode map [string ]* Node
27+
28+ // 关闭 access 权限验证, 默认否
29+ NoAccessVerify bool
30+ // 关闭 request 验证开关, 默认否
31+ NoRequestVerify bool
32+
33+ //Access *config.Access
34+
35+ // dbFieldStyle 数据库字段命名风格 请求传递到数据库中
36+ DbFieldStyle config.FieldStyle
37+
38+ // jsonFieldStyle 数据库返回的字段
39+ JsonFieldStyle config.FieldStyle
40+
41+ Functions * config.Functions
42+ actionConfig * config.ActionConfig
2643}
2744
28- func New (ctx context.Context , method string , req g .Map ) * Action {
45+ func New (ctx context.Context , actionConfig * config. ActionConfig , method string , req model .Map ) * Action {
2946
30- request , err := checkTag (req , method )
47+ request , err := checkTag (req , method , actionConfig )
3148 if err != nil {
3249 panic (err )
3350 }
@@ -36,12 +53,13 @@ func New(ctx context.Context, method string, req g.Map) *Action {
3653 delete (req , "version" )
3754
3855 a := & Action {
39- ctx : ctx ,
40- tagRequest : request ,
41- method : method ,
42- req : req ,
43- children : map [string ]* Node {},
44- keyNode : map [string ]* Node {},
56+ ctx : ctx ,
57+ tagRequest : request ,
58+ method : method ,
59+ req : req ,
60+ children : map [string ]* Node {},
61+ keyNode : map [string ]* Node {},
62+ actionConfig : actionConfig ,
4563 }
4664 return a
4765}
@@ -63,16 +81,19 @@ func (a *Action) parse() error {
6381 }
6482 }
6583
66- var list []g .Map
67- _v , ok := v .(g .Map )
84+ var list []model .Map
85+ _v , ok := v .(model .Map )
6886 if ok { // 将所有node都假设成列表, 如果单个则看成一个元素的批量
69- list = []g .Map {_v }
87+ list = []model .Map {_v }
7088 } else {
71- list = gconv .SliceMap (v )
89+ for _ , m := range gconv .Maps (v ) {
90+ list = append (list , m )
91+ }
7292 }
7393
7494 node := newNode (key , list , structure , a .tagRequest .Executor [key ])
7595 node .ctx = a .ctx
96+ node .action = a
7697 a .keyNode [key ] = & node
7798 node .keyNode = a .keyNode
7899 err := node .parse (a .ctx , a .method )
@@ -86,18 +107,18 @@ func (a *Action) parse() error {
86107 return nil
87108}
88109
89- func (a * Action ) Result () (g .Map , error ) {
110+ func (a * Action ) Result () (model .Map , error ) {
90111
91112 err := a .parse ()
92113 if err != nil {
93114 return nil , err
94115 }
95116
96- ret := g .Map {}
117+ ret := model .Map {}
97118
98119 for _ , k := range a .tagRequest .ExecQueue {
99120 node := a .children [k ]
100- err = EmitHook (a .ctx , BeforeExec , node , a .method )
121+ err = EmitHook (a .ctx , BeforeNodeExec , node , a .method )
101122 if err != nil {
102123 return nil , err
103124 }
@@ -112,9 +133,8 @@ func (a *Action) Result() (g.Map, error) {
112133 }
113134 }
114135
115- err = g .DB ().Transaction (a .ctx , func (ctx context.Context , tx * gdb.TX ) error {
136+ err = g .DB ().Transaction (a .ctx , func (ctx context.Context , tx gdb.TX ) error {
116137 for _ , k := range a .tagRequest .ExecQueue {
117-
118138 node := a .children [k ]
119139 ret [k ], err = node .execute (ctx , a .method )
120140 if err != nil {
@@ -130,7 +150,7 @@ func (a *Action) Result() (g.Map, error) {
130150
131151 for _ , k := range a .tagRequest .ExecQueue {
132152 node := a .children [k ]
133- err = EmitHook (a .ctx , AfterExec , node , a .method )
153+ err = EmitHook (a .ctx , AfterNodeExec , node , a .method )
134154 if err != nil {
135155 return nil , err
136156 }
@@ -139,7 +159,7 @@ func (a *Action) Result() (g.Map, error) {
139159 return ret , err
140160}
141161
142- func checkTag (req g .Map , method string ) (* db .Request , error ) {
162+ func checkTag (req model .Map , method string , requestCfg * config. ActionConfig ) (* config .Request , error ) {
143163 _tag , ok := req ["tag" ]
144164 if ! ok {
145165 return nil , gerror .New ("tag 缺失" )
@@ -148,7 +168,7 @@ func checkTag(req g.Map, method string) (*db.Request, error) {
148168 tag := gconv .String (_tag )
149169 version := req ["version" ]
150170
151- request , err := db .GetRequest (tag , method , gconv .String (version ))
171+ request , err := requestCfg .GetRequest (tag , method , gconv .String (version ))
152172 if err != nil {
153173 return nil , err
154174 }
0 commit comments