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

Commitff2aa50

Browse files
committed
update some
1 parent5c43c8e commitff2aa50

File tree

19 files changed

+293
-269
lines changed

19 files changed

+293
-269
lines changed

‎.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ on:
77

88
jobs:
99
simple-test:
10-
run:cd test && go test -short
10+
runs-on:ubuntu-latest
11+
steps:
12+
-name:test
13+
run:cd test && go test -short

‎.github/workflows/todo.yml

Lines changed: 0 additions & 45 deletions
This file was deleted.

‎@doc/functions.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
##1. 调用方式一 来自返回的字段 -> 因为默认simple字段会返回 -> 需要返回吗
2+
```json
3+
{
4+
"name":"hi",
5+
"aaa":"demo",
6+
"ref()":"sayHello(name,aaa)",
7+
"@a":0,
8+
"ref2()":"ret(@a)",
9+
"User": {
10+
"pic()":"getPic(userId)"// 来自当前User的字段, 需要分析函数依赖的字段和依赖函数字段的节点
11+
}
12+
}
13+
```
14+
15+
##2
16+
```json
17+
{
18+
"msg()":"sayHi",
19+
"msg2()":"sayHi()"
20+
}
21+
```

‎action/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func RegHook(h Hook) {
2828

2929
funcEmitHook(ctx context.Context,hookAtint,node*Node,methodstring)error {
3030

31-
hooks:=append(hooksMap["*"],hooksMap[node.TableName]...)
31+
hooks:=append(hooksMap["*"],hooksMap[node.AccessName]...)
3232
for_,hook:=rangehooks {
3333

3434
varhandlerfunc(ctx context.Context,n*Node,methodstring)error

‎action/node.go

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import (
1414
)
1515

1616
typeNodestruct {
17-
req []model.Map
18-
ctx context.Context
19-
action*Action
20-
Keystring
21-
TableNamestring
22-
Rolestring
17+
req []model.Map
18+
ctx context.Context
19+
action*Action
20+
Keystring
21+
tableNamestring
22+
AccessNamestring
23+
Rolestring
2324

2425
Data []model.Map// 需写入数据库的数据
2526
Where []model.Map// 条件
@@ -34,8 +35,14 @@ type Node struct {
3435
}
3536

3637
funcnewNode(keystring,req []model.Map,structure*config.Structure,executorstring)Node {
38+
39+
accessName:=key
40+
ifstrings.HasSuffix(accessName,"[]") {
41+
accessName=accessName[0 :len(accessName)-2]
42+
}
43+
3744
returnNode{
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
ifkey==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
ifmethod==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
returnerr
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

144150
func (n*Node)checkAccess(ctx context.Context,methodstring,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
ifstrings.HasSuffix(k,consts.RefKeySuffix) {
282286
refNodeKey,refCol:=util.ParseRefCol(v.(string))
283287
ifstrings.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
ifaccess.RowKeyGen!="" {
315319
fori,_:=rangen.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
iferr!=nil {
319323
returnnil,err
320324
}
@@ -332,7 +336,7 @@ func (n *Node) do(ctx context.Context, method string, dataIndex int) (ret model.
332336

333337
varidint64
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
iferr!=nil {
338342
returnnil,err
@@ -350,16 +354,16 @@ func (n *Node) do(ctx context.Context, method string, dataIndex int) (ret model.
350354
ifrowKeyVal!=nil {
351355
fork,v:=rangerowKeyVal {
352356
ifk==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
casehttp.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
iferr!=nil {
364368
returnnil,err
365369
}
@@ -369,7 +373,7 @@ func (n *Node) do(ctx context.Context, method string, dataIndex int) (ret model.
369373
"count":count,
370374
}
371375
casehttp.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
iferr!=nil {
374378
returnnil,err
375379
}

‎config/access.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ func NewConditionRet() *ConditionRet {
2828
return&c
2929
}
3030

31-
func (c*ConditionRet)Add(kstring,vany) {// todo any?
31+
func (c*ConditionRet)Add(kstring,vany) {
3232
c.condition[k]=v
3333
}
3434

35-
func (c*ConditionRet)AddRaw(kstring,vany) {// todo any?
35+
func (c*ConditionRet)AddRaw(kstring,vany) {
3636
c.rawCondition[k]=v
3737
}
3838

‎config/action_config.go

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -50,79 +50,3 @@ func (c *ActionConfig) RowKeyGen(ctx context.Context, genFuncName string, access
5050

5151
returnnil,nil
5252
}
53-
54-
//
55-
//type ExecutorConfig struct {
56-
//NoVerify bool
57-
//accessConfig *AccessConfig
58-
//method string
59-
//role string
60-
//DBMeta *DBMeta
61-
//DbFieldStyle FieldStyle
62-
//JsonFieldStyle FieldStyle
63-
//}
64-
//
65-
//func NewExecutorConfig(accessConfig *AccessConfig, method string, noVerify bool) *ExecutorConfig {
66-
//return &ExecutorConfig{
67-
//accessConfig: accessConfig,
68-
//method: method,
69-
//NoVerify: noVerify,
70-
//}
71-
//}
72-
//
73-
//func (c *ExecutorConfig) SetRole(role string) {
74-
//c.role = role
75-
//}
76-
//
77-
//func (c *ExecutorConfig) TableName() string {
78-
//return c.accessConfig.Name
79-
//}
80-
//
81-
//func (c *ExecutorConfig) TableColumns() []string {
82-
//return c.DBMeta.GetTableColumns(c.accessConfig.Name)
83-
//}
84-
//
85-
//func (c *ExecutorConfig) GetFieldsGetOutByRole() []string {
86-
//var fieldsMap map[string]string
87-
//
88-
//if val, exists := c.accessConfig.FieldsGet[c.role]; exists {
89-
//fieldsMap = val.Out
90-
//} else {
91-
//fieldsMap = c.accessConfig.FieldsGet["default"].Out
92-
//}
93-
//return lo.Keys(fieldsMap)
94-
//}
95-
//
96-
//func (c *ExecutorConfig) GetFieldsGetInByRole() map[string][]string {
97-
//var inFieldsMap map[string][]string
98-
//
99-
//if val, exists := c.accessConfig.FieldsGet[c.role]; exists {
100-
//inFieldsMap = val.In
101-
//} else {
102-
//inFieldsMap = c.accessConfig.FieldsGet["default"].In
103-
//}
104-
//
105-
//return inFieldsMap
106-
//}
107-
//
108-
//func (c *ExecutorConfig) AccessRoles() []string {
109-
//switch c.method {
110-
//case http.MethodGet:
111-
//return c.accessConfig.Get
112-
//case http.MethodHead:
113-
//return c.accessConfig.Head
114-
//case http.MethodPost:
115-
//return c.accessConfig.Post
116-
//case http.MethodPut:
117-
//return c.accessConfig.Put
118-
//case http.MethodDelete:
119-
//return c.accessConfig.Delete
120-
//}
121-
//return []string{}
122-
//
123-
//}
124-
//
125-
//func (c *ExecutorConfig) Executor() string {
126-
//return c.accessConfig.Executor
127-
//
128-
//}

‎config/config.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ type Config struct {
4848
RequestListProviderstring
4949
DbMetaProviderstring
5050

51-
accessList []AccessConfig// todo to access
51+
accessList []AccessConfig
5252

5353
requestConfig*RequestConfig
54-
55-
queryConfig*QueryConfig
56-
actionConfig*ActionConfig
54+
queryConfig*QueryConfig
55+
actionConfig*ActionConfig
5756
}
5857

5958
funcNew()*Config {

‎config/functions.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
)
99

1010
typeFuncstruct {
11-
// todo 调整成结构体
1211
Handlerfunc(ctx context.Context,param model.Map) (resany,errerror)
1312
}
1413

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp