forked from glennliao/apijson-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction_config.go
More file actions
executable file
·82 lines (65 loc) · 2.1 KB
/
action_config.go
File metadata and controls
executable file
·82 lines (65 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package config
import (
"context"
"strings"
"github.com/glennliao/apijson-go/consts"
"github.com/glennliao/apijson-go/model"
"github.com/glennliao/apijson-go/util"
"github.com/gogf/gf/v2/container/gvar"
)
type ActionConfig struct {
requestConfig *RequestConfigs
access *Access
functions *functions
rowKeyGenFuncMap map[string]RowKeyGenerator
defaultRoleFunc DefaultRole
}
func (c *ActionConfig) NoVerify() bool {
return c.access.NoVerify
}
func (c *ActionConfig) DefaultRoleFunc() DefaultRole {
return c.defaultRoleFunc
}
func (c *ActionConfig) GetAccessConfig(key string, noVerify bool) (*AccessConfig, error) {
return c.access.GetAccess(key, noVerify)
}
func (c *ActionConfig) Func(name string) *Func {
return c.functions.funcMap[name]
}
func (c *ActionConfig) CallFunc(ctx context.Context, name string, param model.Map) (res any, err error) {
return c.functions.Call(ctx, name, param)
}
func (c *ActionConfig) GetRequest(tag string, method string, version string) (*RequestConfig, error) {
return c.requestConfig.GetRequest(tag, method, version)
}
func (c *ActionConfig) ConditionFunc(ctx context.Context, req ConditionReq, condition *ConditionRet) error {
return c.access.ConditionFunc(ctx, req, condition)
}
func (c *ActionConfig) RowKeyGen(ctx context.Context, genFuncName string, accessName string, tableName string, data model.Map) (model.Map, error) {
var paramKeys []string
if strings.Contains(genFuncName, "(") {
genFuncName, paramKeys = util.ParseFunctionsStr(genFuncName)
}
if f, exists := c.rowKeyGenFuncMap[genFuncName]; exists {
req := &RowKeyGenReq{
AccessName: accessName,
TableName: tableName,
Data: data,
}
if len(paramKeys) > 0 {
var param = model.FuncParam{}
for i, item := range f.ParamList {
if len(paramKeys) >= i {
param[item.Name] = gvar.New(paramKeys[i])
} else {
param[item.Name] = gvar.New(item.Default)
}
}
req.GenParam = param
}
ret := NewRowKeyGenRet()
err := f.Handler(ctx, req, ret)
return ret.data, err
}
return nil, consts.NewSysErr("rowKey RowKeyGenerator not found:" + genFuncName)
}