Skip to content

Commit 5c43c8e

Browse files
committed
## 0.2.0-alpha
1 parent 3201fab commit 5c43c8e

File tree

7 files changed

+62
-38
lines changed

7 files changed

+62
-38
lines changed

action/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Action struct {
3030
// 关闭 request 验证开关, 默认否
3131
NoRequestVerify bool
3232

33-
Access *config.Access
33+
//Access *config.Access
3434

3535
// dbFieldStyle 数据库字段命名风格 请求传递到数据库中
3636
DbFieldStyle config.FieldStyle

action/node.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Node struct {
3030

3131
keyNode map[string]*Node
3232

33-
access *config.Access
33+
//access *config.Access
3434
}
3535

3636
func newNode(key string, req []model.Map, structure *config.Structure, executor string) Node {
@@ -80,7 +80,7 @@ func (n *Node) parse(ctx context.Context, method string) error {
8080
if strings.HasSuffix(key, consts.ListKeySuffix) {
8181
key = key[0 : len(key)-2]
8282
}
83-
access, err := n.access.GetAccess(key, true)
83+
access, err := n.action.actionConfig.GetAccessConfig(key, true)
8484

8585
if err != nil {
8686
return err
@@ -145,7 +145,7 @@ func (n *Node) checkAccess(ctx context.Context, method string, accessRoles []str
145145

146146
// todo 可配置单次的内容, 而非直接使用整个的
147147

148-
role, err := n.action.Access.DefaultRoleFunc(ctx, config.RoleReq{
148+
role, err := n.action.actionConfig.DefaultRoleFunc()(ctx, config.RoleReq{
149149
AccessName: n.TableName,
150150
Method: method,
151151
NodeRole: n.Role,
@@ -177,7 +177,7 @@ func (n *Node) checkAccess(ctx context.Context, method string, accessRoles []str
177177
NodeReq: item,
178178
}
179179

180-
err := n.action.Access.ConditionFunc(ctx, conditionReq, condition)
180+
err := n.action.actionConfig.ConditionFunc(ctx, conditionReq, condition)
181181

182182
if err != nil {
183183
return err
@@ -306,7 +306,7 @@ func (n *Node) do(ctx context.Context, method string, dataIndex int) (ret model.
306306

307307
var rowKeyVal model.Map
308308

309-
access, err := n.access.GetAccess(n.Key, true)
309+
access, err := n.action.actionConfig.GetAccessConfig(n.Key, true)
310310
if err != nil {
311311
return nil, err
312312
}

config/action_config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
type ActionConfig struct {
9-
requestConfig RequestConfig
9+
requestConfig *RequestConfig
1010
access *Access
1111
functions *Functions
1212
rowKeyGenFuncMap map[string]RowKeyGenFuncHandler
@@ -33,6 +33,10 @@ func (c *ActionConfig) GetRequest(tag string, method string, version string) (*R
3333
return c.requestConfig.GetRequest(tag, method, version)
3434
}
3535

36+
func (c *ActionConfig) ConditionFunc(ctx context.Context, req ConditionReq, condition *ConditionRet) error {
37+
return c.access.ConditionFunc(ctx, req, condition)
38+
}
39+
3640
func (c *ActionConfig) RowKeyGen(ctx context.Context, genFuncName string, accessName string, data model.Map) (model.Map, error) {
3741
if f, exists := c.rowKeyGenFuncMap[genFuncName]; exists {
3842
req := &RowKeyGenReq{

config/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ func (c *Config) ReLoad() {
114114
maxTreeWidth: c.MaxTreeWidth,
115115
defaultRoleFunc: c.Access.DefaultRoleFunc,
116116
}
117+
118+
c.actionConfig = &ActionConfig{
119+
requestConfig: c.requestConfig,
120+
access: c.Access,
121+
functions: c.Functions,
122+
rowKeyGenFuncMap: c.rowKeyGenFuncMap,
123+
defaultRoleFunc: c.Access.DefaultRoleFunc,
124+
}
117125
}
118126

119127
func (c *Config) QueryConfig() *QueryConfig {

config/request_config.go

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ import (
1010
)
1111

1212
type Request struct {
13-
Debug int8
14-
Version string
15-
Method string
16-
Tag string
17-
StructureDb map[string]any `orm:"structure"`
18-
Structure map[string]*Structure `orm:"-"`
19-
Detail string
20-
CreatedAt *gtime.Time
13+
Debug int8
14+
Version string
15+
Method string
16+
Tag string
17+
Structure map[string]*Structure
18+
Detail string
19+
CreatedAt *gtime.Time
2120
// 节点执行顺序
2221
ExecQueue []string
2322
Executor map[string]string
@@ -51,35 +50,40 @@ func NewRequestConfig(requestList []Request) *RequestConfig {
5150
item := _item
5251
tag, _ := getTag(item.Tag)
5352

54-
if strings.ToLower(tag) != tag {
55-
// 本身大写, 如果没有外层, 则套一层
56-
if _, ok := item.StructureDb[tag]; !ok {
57-
item.StructureDb = map[string]any{
58-
tag: item.StructureDb,
59-
}
60-
}
53+
if item.Structure == nil {
54+
item.Structure = make(map[string]*Structure)
6155
}
6256

63-
item.Structure = make(map[string]*Structure)
64-
//for k, v := range item.StructureDb {
65-
// structure := Structure{}
66-
// err := gconv.Scan(v, &structure)
67-
// if err != nil {
68-
// panic(err)
69-
// }
70-
//
71-
// if structure.Must != nil {
72-
// structure.Must = strings.Split(structure.Must[0], ",")
73-
// }
74-
// if structure.Refuse != nil {
75-
// structure.Refuse = strings.Split(structure.Refuse[0], ",")
57+
// provider处理
58+
//if strings.ToLower(tag) != tag {
59+
// // 本身大写, 如果没有外层, 则套一层
60+
// if _, ok := item.Structure[tag]; !ok {
61+
// item.Structure = map[string]any{
62+
// tag: item.Structure,
63+
// }
7664
// }
77-
//
78-
// item.Structure[k] = &structure
7965
//}
8066

67+
for k, v := range item.Structure {
68+
structure := Structure{}
69+
err := gconv.Scan(v, &structure)
70+
if err != nil {
71+
panic(err)
72+
}
73+
74+
if structure.Must != nil {
75+
structure.Must = strings.Split(structure.Must[0], ",")
76+
}
77+
if structure.Refuse != nil {
78+
structure.Refuse = strings.Split(structure.Refuse[0], ",")
79+
}
80+
81+
item.Structure[k] = &structure
82+
}
83+
8184
if len(item.ExecQueue) > 0 {
82-
item.ExecQueue = strings.Split(item.ExecQueue[0], ",")
85+
// todo db provider处理
86+
//item.ExecQueue = strings.Split(item.ExecQueue[0], ",")
8387
} else {
8488
item.ExecQueue = []string{tag}
8589
}

drivers/framework_goframe/gf.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ func (gf *GF) commonResponse(handler func(ctx context.Context, req model.Map) (r
102102
}
103103
}
104104

105+
if err != nil {
106+
panic(err)
107+
}
108+
105109
})
106110

107111
if err != nil {

query/node_struct.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ func (h *structNode) result() {
123123
}
124124

125125
n.ret = retList
126+
127+
if len(n.ret.([]model.Map)) == 0 {
128+
n.ret = []model.Map{}
129+
}
126130
} else {
127131

128132
retMap := model.Map{}

0 commit comments

Comments
 (0)