-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
64 lines (51 loc) · 2.28 KB
/
config.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
package ginKit
type (
Config struct {
Mode string `json:"mode" yaml:"mode" validate:"omitempty,oneof=debug release test"`
HostName string `json:"hostName" yaml:"hostName" validate:"omitempty,hostname|ipv4"`
// Port
/*
0(默认): 不使用 http port
*/
Port int `json:"port" yaml:"port" validate:"port|eq=0,necsfield=SSL.Port"`
DisableColor bool `json:"disableColor" yaml:"disableColor"`
Pprof bool `json:"pprof" yaml:"pprof"`
SSL SslConfig `json:"ssl" yaml:"ssl"`
Middleware MiddlewareConfig `json:"middleware" yaml:"middleware"`
}
SslConfig struct {
// Port
/*
0(默认): 不使用 https port
*/
Port int `json:"port" yaml:"port" validate:"port|eq=0"`
CertFile string `json:"certFile" yaml:"certFile" validate:"file_unless=Port 0"`
KeyFile string `json:"keyFile" yaml:"keyFile" validate:"file_unless=Port 0"`
}
MiddlewareConfig struct {
BodyLimit int64 `json:"bodyLimit" yaml:"bodyLimit"`
//Gzip int `json:"gzip" yaml:"gzip" validate:"min=-1,max=9"`
//XFrameOptions string `json:"xFrameOptions" yaml:"xFrameOptions" validate:"omitempty,lowercase,oneof=deny sameorigin|startswith=allow-from "`
Gzip *GzipConfig `json:"gzip" yaml:"gzip"`
Cors CorsConfig `json:"cors" yaml:"cors"`
RateLimiter *RateLimiterConfig `json:"rateLimiter" yaml:"rateLimiter"`
ResponseHeaders map[string]string `json:"responseHeaders" yaml:"responseHeaders" mapstructure:"responseHeaders"`
}
// CorsConfig cors(跨源资源共享)的配置
CorsConfig struct {
Access bool `json:"access" yaml:"access"`
Origins []string `json:"origins" yaml:"origins" validate:"unique,dive,required"`
}
// RateLimiterConfig 限流器(令牌桶算法)的配置
RateLimiterConfig struct {
R int `json:"r" yaml:"r" validate:"gt=0"`
B int `json:"b" yaml:"b" validate:"gt=0,gtecsfield=R"`
}
GzipConfig struct {
Level int `json:"level" yaml:"level" validate:"min=-1,max=9"`
//MinContentLength int64 `json:"minContentLength" yaml:"minContentLength" validate:"gt=0"`
ExcludedExtensions []string `json:"excludedExtensions" yaml:"excludedExtensions"`
ExcludedPaths []string `json:"excludedPaths" yaml:"excludedPaths"`
ExcludedPathsRegexps []string `json:"excludedPathsRegexps" yaml:"excludedPathsRegexps"`
}
)