-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
55 lines (46 loc) · 944 Bytes
/
option.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
package ginx
import "github.com/gin-gonic/gin"
var (
defaultOpt = option{
cookieAge: 604800,
cookieKey: CookieKey,
recoverable: true,
logRequest: false,
}
)
type option struct {
cookieAge int
cookieKey string
recoverable bool
logRequest bool
middlewares []gin.HandlerFunc
}
type OptionFn func(*option)
func WithCookieAge(age int) OptionFn {
return func(o *option) {
o.cookieAge = age
}
}
func WithRecovery(enable bool) OptionFn {
return func(o *option) {
o.recoverable = enable
}
}
func WithLogRequest(enable bool) OptionFn {
return func(o *option) {
o.logRequest = enable
}
}
func WithMiddleware(middlewares ...gin.HandlerFunc) OptionFn {
return func(o *option) {
if o.middlewares == nil {
o.middlewares = make([]gin.HandlerFunc, 0)
}
o.middlewares = append(o.middlewares, middlewares...)
}
}
func WithCookieKey(key string) OptionFn {
return func(o *option) {
o.cookieKey = key
}
}