forked from glennliao/apijson-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathz_app_test.go
executable file
·96 lines (85 loc) · 1.84 KB
/
z_app_test.go
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"context"
"time"
"github.com/glennliao/apijson-go"
"github.com/glennliao/apijson-go/config"
"github.com/glennliao/apijson-go/config/tables"
"github.com/glennliao/apijson-go/model"
"github.com/glennliao/table-sync/tablesync"
"github.com/gogf/gf/v2/frame/g"
)
type User struct {
Id uint32 `ddl:"primaryKey"`
Username string
Password string
CreatedAt *time.Time
UpdatedAt *time.Time
}
type Todo struct {
Id uint32 `ddl:"primaryKey"`
UserId uint32
Content string
CreatedAt *time.Time
}
func init() {
config.RegAccessListProvider("db", func(ctx context.Context) []config.AccessConfig {
return []config.AccessConfig{
{
Name: "user",
Alias: "User",
Get: []string{"UNKNOWN"},
RowKey: "id",
FieldsGet: map[string]*config.FieldsGetValue{
"default": {
In: nil,
Out: map[string]string{
"id": "",
"username": "",
},
MaxCount: nil,
},
},
},
{
Name: "user",
Alias: "User2",
Get: []string{"UNKNOWN"},
RowKey: "id",
},
}
})
}
func App(ctx context.Context, a *apijson.ApiJson) {
syncer := tablesync.Syncer{
Tables: []tablesync.Table{
User{}, Todo{},
tables.Access{}, tables.Request{},
},
}
err := syncer.Sync(ctx, g.DB())
if err != nil {
panic(err)
}
a.Config().Functions.Bind("test", config.Func{
Handler: func(ctx context.Context, param model.FuncParam) (res any, err error) {
return "你好", nil
},
})
a.Config().Functions.Bind("concat", config.Func{
ParamList: []config.ParamItem{
{
Name: "a",
Type: "string",
},
{
Name: "b",
Type: "string",
},
},
Handler: func(ctx context.Context, param model.FuncParam) (res any, err error) {
return param["a"].String() + param["b"].String(), nil
},
})
// a.Config().AccessListProvider = "custom"
}