-
Notifications
You must be signed in to change notification settings - Fork 0
/
routing.go
59 lines (55 loc) · 1.35 KB
/
routing.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
package app
import (
"io/fs"
"zestack.dev/slim"
)
// RoutingConfig 路由配置
type RoutingConfig struct {
ErrorHandler slim.ErrorHandlerFunc
Validator slim.Validator
Renderer slim.Renderer
Filesystem fs.FS
JSONSerializer slim.Serializer
XMLSerializer slim.Serializer
MultipartMemoryLimit int64 // 文件上传大小限制
PrettyIndent string // json/xml 格式化缩进
JSONPCallbacks []string
RouterCreator func(s *slim.Slim) slim.Router
Middleware []slim.MiddlewareFunc
Negotiator *slim.Negotiator
}
func (c RoutingConfig) use(s *slim.Slim) {
if c.ErrorHandler != nil {
s.ErrorHandler = c.ErrorHandler
}
if c.Validator != nil {
s.Validator = c.Validator
}
if c.Renderer != nil {
s.Renderer = c.Renderer
}
if c.Filesystem != nil {
s.Filesystem = c.Filesystem
}
if c.JSONSerializer != nil {
s.JSONSerializer = c.JSONSerializer
}
if c.XMLSerializer != nil {
s.XMLSerializer = c.XMLSerializer
}
if c.MultipartMemoryLimit > 0 {
s.MultipartMemoryLimit = c.MultipartMemoryLimit
}
if len(c.JSONPCallbacks) > 0 {
s.JSONPCallbacks = c.JSONPCallbacks[:]
}
if c.RouterCreator != nil {
s.ResetRouterCreator(c.RouterCreator)
}
if len(c.Middleware) > 0 {
s.Use(c.Middleware...)
}
if c.Negotiator != nil {
s.SetNegotiator(c.Negotiator)
}
}