-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmode.go
108 lines (87 loc) · 1.79 KB
/
mode.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
97
98
99
100
101
102
103
104
105
106
107
108
package router
import (
"github.com/gin-gonic/gin"
"github.com/gouef/mode"
)
func (r *Router) IsMode(mode string) bool {
m, err := r.Mode.IsMode(mode)
if err != nil {
return false
}
return m
}
func (r *Router) EnableMode(mode string) bool {
m, err := r.Mode.EnableMode(mode)
if err != nil {
return false
}
switch mode {
case DebugMode:
EnableDebug()
case ReleaseMode:
EnableRelease()
default:
EnableTest()
}
return m
}
func (r *Router) IsDebug() bool {
return r.IsMode(mode.DebugMode)
}
func (r *Router) EnableDebug() bool {
return r.EnableMode(mode.DebugMode)
}
func (r *Router) IsTest() bool {
return r.IsMode(mode.TestMode)
}
func (r *Router) EnableTest() bool {
return r.EnableMode(mode.TestMode)
}
func (r *Router) IsRelease() bool {
return r.IsMode(mode.ReleaseMode)
}
// EnableRelease set Mode release for project and gin
func (r *Router) EnableRelease() bool {
return r.EnableMode(mode.ReleaseMode)
}
// SetMode set Mode for project and gin
func (r *Router) SetMode(mode string) *Router {
r.EnableMode(mode)
return r
}
// SetMode set Mode for gin
func SetMode(mode string) {
gin.SetMode(mode)
}
// GetMode return gin Mode
func GetMode() string {
return gin.Mode()
}
// GetMode return project Mode
func (r *Router) GetMode() string {
return r.Mode.GetMode()
}
// IsDebug if gin Mode is debug
func IsDebug() bool {
return gin.IsDebugging()
}
// EnableDebug set Mode debug for gin
func EnableDebug() {
SetMode(DebugMode)
}
// IsTest if gin Mode is test
func IsTest() bool {
return gin.Mode() == TestMode
}
// EnableTest set Mode test for gin
func EnableTest() {
SetMode(TestMode)
}
// IsRelease if gin Mode is release
func IsRelease() bool {
return gin.Mode() == ReleaseMode
}
// EnableRelease set Mode release for gin
func EnableRelease() {
SetMode(ReleaseMode)
}