forked from glennliao/apijson-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrowkeygen.go
More file actions
executable file
·65 lines (52 loc) · 1.3 KB
/
rowkeygen.go
File metadata and controls
executable file
·65 lines (52 loc) · 1.3 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
package config
import (
"context"
"github.com/glennliao/apijson-go/consts"
"github.com/glennliao/apijson-go/model"
"github.com/samber/lo"
)
type RowKeyGenReq struct {
AccessName string
TableName string
GenParam model.FuncParam
Data model.Map
}
type RowKeyGenFuncHandler func(ctx context.Context, req *RowKeyGenReq, ret *RowKeyGenRet) error
type RowKeyGenerator struct {
Name string
ParamList []ParamItem
Handler RowKeyGenFuncHandler
}
type RowKeyGenRet struct {
data model.Map
}
func NewRowKeyGenRet() *RowKeyGenRet {
return &RowKeyGenRet{data: map[string]any{}}
}
func (r *RowKeyGenRet) RowKey(id any) {
r.data[consts.RowKey] = id
}
func (r *RowKeyGenRet) RowKeys(d model.Map) {
for k, v := range d {
r.data[k] = v
}
}
// func (c *Config) RowKeyGen(ctx context.Context, genFuncName string, accessName string, data model.Map) (model.Map, error) {
// if f, exists := c.rowKeyGenFuncMap[genFuncName]; exists {
// req := &RowKeyGenReq{
// AccessName: accessName,
// Data: data,
// }
// ret := NewRowKeyGenRet()
// err := f.Handler(ctx, req, ret)
// return ret.data, err
// }
//
// return nil, nil
// }
func (c *Config) RowKeyGenFunc(f RowKeyGenerator) {
c.rowKeyGenFuncMap[f.Name] = f
}
func (c *Config) RowKeyGenList() []string {
return lo.Keys(c.rowKeyGenFuncMap)
}