-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
59 lines (50 loc) · 1.72 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
package ginKit
import (
"github.com/richelieu-yang/chimera/v2/src/core/fileKit"
"github.com/richelieu-yang/chimera/v2/src/core/interfaceKit"
"github.com/richelieu-yang/chimera/v2/src/web/refererKit"
)
type (
Config struct {
Mode string `json:"mode,default=debug,options=debug|release|test"`
HostName string `json:"hostName,optional"`
Port int `json:"port,default=80,range=[1:65535]"`
Colorful bool `json:"colorful,default=true"`
Pprof bool `json:"pprof,default=false"`
SSL SslConfig `json:"ssl"`
Middleware MiddlewareConfig `json:"middleware"`
}
SslConfig struct {
Access bool `json:"access,default=false"`
CertFile string `json:"certFile,optional"`
KeyFile string `json:"keyFile,optional"`
}
MiddlewareConfig struct {
BodyLimit int64 `json:"bodyLimit,default=-1,range=[-1:]"`
Gzip bool `json:"gzip,default=false"`
XFrameOptions string `json:"xFrameOptions,optional"`
Cors CorsConfig `json:"cors"`
Referer []*refererKit.RefererVerifierBuilder `json:"referer,optional"`
}
// CorsConfig cors(跨源资源共享)的配置
CorsConfig struct {
Access bool `json:"access,default=false"`
Origins []string `json:"origins,optional"`
}
)
func (config *Config) Verify() error {
if err := interfaceKit.AssertNotNil(config, "config"); err != nil {
return err
}
// ssl
sslConfig := config.SSL
if sslConfig.Access {
if err := fileKit.AssertExistAndIsFile(sslConfig.CertFile); err != nil {
return err
}
if err := fileKit.AssertExistAndIsFile(sslConfig.KeyFile); err != nil {
return err
}
}
return nil
}