@@ -26,13 +26,7 @@ func init() {
2626 IdleTimeoutSecond : 300 ,
2727 MaxHeaderSize : "16kb" ,
2828 EnableTrace : true ,
29- Cors : CORS {
30- Enabled : false ,
31- AllowedHeaders : []string {"*" },
32- AllowedDomains : []string {"*" },
33- AllowedMethods : []string {"HEAD" , "OPTIONS" , "GET" , "POST" , "PUT" , "PATCH" , "DELETE" },
34- },
35- WEB_FRAMEWORK : WEB_FRAMEWORK_AUTO ,
29+ WEB_FRAMEWORK : WEB_FRAMEWORK_AUTO ,
3630 routerBuilders : map [WEB_FRAMEWORK ]RouterBuilder {
3731 WEB_FRAMEWORK_GO_RESTFUL : NewGoRestfulRouterBuilder (),
3832 WEB_FRAMEWORK_GIN : NewGinRouterBuilder (),
@@ -41,7 +35,6 @@ func init() {
4135 WEB_FRAMEWORK_GO_RESTFUL : 0 ,
4236 WEB_FRAMEWORK_GIN : 0 ,
4337 },
44- RouterBuildConfig : & BuildConfig {},
4538 })
4639}
4740
@@ -72,23 +65,15 @@ type Http struct {
7265 // header最大大小
7366 MaxHeaderSize string `json:"max_header_size" yaml:"max_header_size" toml:"max_header_size" env:"MAX_HEADER_SIZE"`
7467
75- // SSL启用参数
76- EnableSSL bool `json:"enable_ssl" yaml:"enable_ssl" toml:"enable_ssl" env:"ENABLE_SSL"`
77- CertFile string `json:"cert_file" yaml:"cert_file" toml:"cert_file" env:"CERT_FILE"`
78- KeyFile string `json:"key_file" yaml:"key_file" toml:"key_file" env:"KEY_FILE"`
79-
8068 // 开启Trace
8169 EnableTrace bool `toml:"enable_trace" json:"enable_trace" yaml:"enable_trace" env:"ENABLE_TRACE"`
82- // cors配置
83- Cors CORS `toml:"cors" json:"cors" yaml:"cors" envPrefix:"CORS_"`
8470
8571 // 解析后的数据
86- maxHeaderBytes uint64
87- log * zerolog.Logger
88- server * http.Server
89- routerBuilders map [WEB_FRAMEWORK ]RouterBuilder `json:"-" yaml:"-" toml:"-" env:"-"`
90- handlerCount map [WEB_FRAMEWORK ]int `json:"-" yaml:"-" toml:"-" env:"-"`
91- RouterBuildConfig * BuildConfig `json:"-" yaml:"-" toml:"-" env:"-"`
72+ maxHeaderBytes uint64
73+ log * zerolog.Logger
74+ server * http.Server
75+ routerBuilders map [WEB_FRAMEWORK ]RouterBuilder `json:"-" yaml:"-" toml:"-" env:"-"`
76+ handlerCount map [WEB_FRAMEWORK ]int `json:"-" yaml:"-" toml:"-" env:"-"`
9277}
9378
9479func (h * Http ) HTTPPrefix () string {
@@ -99,17 +84,6 @@ func (h *Http) HTTPPrefix() string {
9984 return u
10085}
10186
102- type HealthCheck struct {
103- Enabled bool `toml:"enabled" json:"enabled" yaml:"enabled" env:"ENABLED"`
104- }
105-
106- type CORS struct {
107- Enabled bool `toml:"enabled" json:"enabled" yaml:"enabled" env:"ENABLED"`
108- AllowedHeaders []string `json:"cors_allowed_headers" yaml:"cors_allowed_headers" toml:"cors_allowed_headers" env:"ALLOWED_HEADERS" envSeparator:","`
109- AllowedDomains []string `json:"cors_allowed_domains" yaml:"cors_allowed_domains" toml:"cors_allowed_domains" env:"ALLOWED_DOMAINS" envSeparator:","`
110- AllowedMethods []string `json:"cors_allowed_methods" yaml:"cors_allowed_methods" toml:"cors_allowed_methods" env:"ALLOWED_METHODS" envSeparator:","`
111- }
112-
11387type WEB_FRAMEWORK string
11488
11589const (
@@ -119,20 +93,6 @@ const (
11993 WEB_FRAMEWORK_GIN WEB_FRAMEWORK = "gin"
12094)
12195
122- type RouterBuilder interface {
123- Config (* BuildConfig )
124- Build () (http.Handler , error )
125- }
126-
127- type BuildHook func (http.Handler )
128-
129- type BuildConfig struct {
130- // 装载Ioc路由之前
131- BeforeLoad BuildHook `json:"-" yaml:"-" toml:"-" env:"-"`
132- // 装载Ioc路由之后
133- AfterLoad BuildHook `json:"-" yaml:"-" toml:"-" env:"-"`
134- }
135-
13696func (h * Http ) setEnable (v bool ) {
13797 h .Enable = & v
13898}
@@ -213,9 +173,6 @@ func (h *Http) BuildRouter() error {
213173 return fmt .Errorf ("router builder for web framework %s not found" , h .WEB_FRAMEWORK )
214174 }
215175
216- // 传递配置
217- rb .Config (h .RouterBuildConfig )
218-
219176 r , err := rb .Build ()
220177 if err != nil {
221178 return err
0 commit comments