-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
72 lines (62 loc) · 1.91 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
65
66
67
68
69
70
71
72
package gohttp
// Config config
type Config struct {
Debug bool `json:"debug" yaml:"debug"`
Addr string `json:"addr" yaml:"addr"`
ReadTimeout int `json:"readtimeout" yaml:"readtimeout"`
ReadHeaderTimeout int `json:"readheadertime" yaml:"readheadertime"`
WriteTimeout int `json:"writetime" yaml:"writetime"`
MaxHeaderBytes int `json:"maxheaderbytes" yaml:"maxheaderbytes"`
CertFile string `json:"cert" yaml:"cert"`
KeyFile string `json:"key" yaml:"key"`
WebPath string `json:"web_path" yaml:"web_path"`
StaticPath []string `json:"static_path" yaml:"static_path"`
LogFormat string `json:"log_format" yaml:"log_format"`
}
// SetDebug set debug model
func (cfg *Config) SetDebug(debug bool) {
cfg.Debug = debug
}
// SetLogFormat set log format
func (cfg *Config) SetLogFormat(format string) {
cfg.LogFormat = format
}
// SetAddress set address
func (cfg *Config) SetAddress(addr string) {
cfg.Addr = addr
}
// SetTimeout set time out
func (cfg *Config) SetTimeout(timeout int) {
cfg.ReadTimeout = timeout
cfg.ReadHeaderTimeout = timeout
cfg.WriteTimeout = timeout
}
// SetMaxHeaderBytes set max header bytes
func (cfg *Config) SetMaxHeaderBytes(max int) {
cfg.MaxHeaderBytes = max
}
// SetTLS set tls
func (cfg *Config) SetTLS(cert, key string) {
cfg.CertFile = cert
cfg.KeyFile = key
}
// SetWebPath set web path
func (cfg *Config) SetWebPath(web string) {
cfg.WebPath = web
}
// SetStaticPath set static path
func (cfg *Config) SetStaticPath(static ...string) {
cfg.StaticPath = append(cfg.StaticPath, static...)
}
// InitConfig init config
func InitConfig() *Config {
cfg := new(Config)
cfg.SetDebug(true)
cfg.SetLogFormat("%3d %s %s (%s) %s")
cfg.SetAddress(":18081")
cfg.SetTimeout(30)
cfg.SetMaxHeaderBytes(1 << 20) //DefaultMaxHeaderBytes 1MB
cfg.SetStaticPath(".")
cfg.SetWebPath(".")
return cfg
}