-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatr.go
72 lines (60 loc) · 1.59 KB
/
atr.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
package atrg
import (
"github.com/agxmaster/atrg/core"
"github.com/agxmaster/atrg/handler"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
func SetUp(db *gorm.DB, g *gin.Engine, opts ...core.Option) {
core.Mp = &core.Config{
Iatr: &handler.Atr{},
RoutePrefix: core.RouterPrefix,
CustomRouterPrefix: core.CustomRouterPrefix,
SuccessCode: core.CodeSuccess,
ErrorCode: core.CodeAtrError,
}
core.Db = db
core.Mp.Apply(opts)
core.AtrRouter(g)
}
func WithCustomHandler(handlerStruct core.Iatr) core.Option {
return core.Option{Fn: func(o *core.Config) {
o.Iatr = handlerStruct
}}
}
func WithModelConfig(fn core.SetModel) core.Option {
return core.Option{Fn: func(o *core.Config) {
o.ModelMap = fn()
}}
}
func WithCustomRoute(fn core.SetCustomModel) core.Option {
return core.Option{Fn: func(o *core.Config) {
o.CustomModelMap = fn()
core.SetCustomModelCache()
}}
}
func WithSuccessCode(code int) core.Option {
return core.Option{Fn: func(o *core.Config) {
o.SuccessCode = core.ResponseCode(code)
}}
}
func WithErrorCode(code int) core.Option {
return core.Option{Fn: func(o *core.Config) {
o.ErrorCode = core.ResponseCode(code)
}}
}
func WithCustomRouterPrefix(routerPrefix string) core.Option {
return core.Option{Fn: func(o *core.Config) {
o.CustomRouterPrefix = routerPrefix
}}
}
func WithRouterPrefix(routerPrefix string) core.Option {
return core.Option{Fn: func(o *core.Config) {
o.RoutePrefix = routerPrefix
}}
}
func WithRules(rules core.Rules) core.Option {
return core.Option{Fn: func(o *core.Config) {
o.Rules = rules
}}
}