@@ -14,12 +14,13 @@ import (
1414)
1515
1616type Node struct {
17- req []model.Map
18- ctx context.Context
19- action * Action
20- Key string
21- TableName string
22- Role string
17+ req []model.Map
18+ ctx context.Context
19+ action * Action
20+ Key string
21+ tableName string
22+ AccessName string
23+ Role string
2324
2425 Data []model.Map // 需写入数据库的数据
2526 Where []model.Map // 条件
@@ -34,8 +35,14 @@ type Node struct {
3435}
3536
3637func newNode (key string , req []model.Map , structure * config.Structure , executor string ) Node {
38+
39+ accessName := key
40+ if strings .HasSuffix (accessName , "[]" ) {
41+ accessName = accessName [0 : len (accessName )- 2 ]
42+ }
43+
3744 return Node {
38- Key : key , req : req , structure : structure , executor : executor ,
45+ Key : key , req : req , structure : structure , executor : executor , AccessName : accessName ,
3946 }
4047}
4148
@@ -52,7 +59,7 @@ func (n *Node) parseReq(method string) {
5259 if key == consts .Role {
5360 n .Role = util .String (val )
5461 } else {
55- key = n .action .DbFieldStyle (n .ctx , n .TableName , key )
62+ key = n .action .DbFieldStyle (n .ctx , n .tableName , key )
5663
5764 if method == http .MethodDelete {
5865 n.Where [i ][key ] = val
@@ -63,7 +70,6 @@ func (n *Node) parseReq(method string) {
6370 } else {
6471 n.Data [i ][key ] = val
6572 }
66- // Post 暂原则上不让传递这个rowKey值 // todo 可传递
6773 } else {
6874 n.Data [i ][key ] = val
6975 }
@@ -86,7 +92,7 @@ func (n *Node) parse(ctx context.Context, method string) error {
8692 return err
8793 }
8894
89- n .TableName = access .Name
95+ n .tableName = access .Name
9096 n .RowKey = access .RowKey
9197
9298 n .parseReq (method )
@@ -143,10 +149,8 @@ func (n *Node) roleUpdate() error {
143149
144150func (n * Node ) checkAccess (ctx context.Context , method string , accessRoles []string ) error {
145151
146- // todo 可配置单次的内容, 而非直接使用整个的
147-
148152 role , err := n .action .actionConfig .DefaultRoleFunc ()(ctx , config.RoleReq {
149- AccessName : n .TableName ,
153+ AccessName : n .tableName ,
150154 Method : method ,
151155 NodeRole : n .Role ,
152156 })
@@ -170,7 +174,7 @@ func (n *Node) checkAccess(ctx context.Context, method string, accessRoles []str
170174 condition := config .NewConditionRet ()
171175
172176 conditionReq := config.ConditionReq {
173- AccessName : n .TableName ,
177+ AccessName : n .tableName ,
174178 TableAccessRoleList : accessRoles ,
175179 Method : method ,
176180 NodeRole : n .Role ,
@@ -281,9 +285,9 @@ func (n *Node) reqUpdateBeforeDo() error {
281285 if strings .HasSuffix (k , consts .RefKeySuffix ) {
282286 refNodeKey , refCol := util .ParseRefCol (v .(string ))
283287 if strings .HasSuffix (refNodeKey , consts .ListKeySuffix ) { // 双列表
284- n.Data [i ][k ] = n .keyNode [refNodeKey ].Data [i ][n .action .DbFieldStyle (n .ctx , n .TableName , refCol )]
288+ n.Data [i ][k ] = n .keyNode [refNodeKey ].Data [i ][n .action .DbFieldStyle (n .ctx , n .tableName , refCol )]
285289 } else {
286- n.Data [i ][k ] = n .keyNode [refNodeKey ].Data [0 ][n .action .DbFieldStyle (n .ctx , n .TableName , refCol )]
290+ n.Data [i ][k ] = n .keyNode [refNodeKey ].Data [0 ][n .action .DbFieldStyle (n .ctx , n .tableName , refCol )]
287291 }
288292 }
289293 }
@@ -314,7 +318,7 @@ func (n *Node) do(ctx context.Context, method string, dataIndex int) (ret model.
314318 if access .RowKeyGen != "" {
315319 for i , _ := range n .Data {
316320
317- rowKeyVal , err = n .action .actionConfig .RowKeyGen (ctx , access .RowKeyGen , n .TableName , n .Data [i ])
321+ rowKeyVal , err = n .action .actionConfig .RowKeyGen (ctx , access .RowKeyGen , n .AccessName , n .Data [i ])
318322 if err != nil {
319323 return nil , err
320324 }
@@ -332,7 +336,7 @@ func (n *Node) do(ctx context.Context, method string, dataIndex int) (ret model.
332336
333337 var id int64
334338
335- id , count , err = executor .GetActionExecutor (n .executor ).Insert (ctx , n .TableName , n .Data )
339+ id , count , err = executor .GetActionExecutor (n .executor ).Insert (ctx , n .tableName , n .Data )
336340
337341 if err != nil {
338342 return nil , err
@@ -350,16 +354,16 @@ func (n *Node) do(ctx context.Context, method string, dataIndex int) (ret model.
350354 if rowKeyVal != nil {
351355 for k , v := range rowKeyVal {
352356 if k == consts .RowKey {
353- ret [jsonStyle (ctx , n .TableName , access .RowKey )] = v
357+ ret [jsonStyle (ctx , n .tableName , access .RowKey )] = v
354358 } else {
355- ret [jsonStyle (ctx , n .TableName , k )] = v
359+ ret [jsonStyle (ctx , n .tableName , k )] = v
356360 }
357361 }
358362 }
359363 }
360364
361365 case http .MethodPut :
362- count , err = executor .GetActionExecutor (n .executor ).Update (ctx , n .TableName , n .Data [dataIndex ], n .Where [dataIndex ])
366+ count , err = executor .GetActionExecutor (n .executor ).Update (ctx , n .tableName , n .Data [dataIndex ], n .Where [dataIndex ])
363367 if err != nil {
364368 return nil , err
365369 }
@@ -369,7 +373,7 @@ func (n *Node) do(ctx context.Context, method string, dataIndex int) (ret model.
369373 "count" : count ,
370374 }
371375 case http .MethodDelete :
372- count , err = executor .GetActionExecutor (n .executor ).Delete (ctx , n .TableName , n .Where [dataIndex ])
376+ count , err = executor .GetActionExecutor (n .executor ).Delete (ctx , n .tableName , n .Where [dataIndex ])
373377 if err != nil {
374378 return nil , err
375379 }
0 commit comments