Skip to content

Commit 033294b

Browse files
committed
补充Debug
1 parent a5ee4c1 commit 033294b

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

examples/http_go_restful/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
"github.com/infraboard/mcube/v2/ioc"
88
"github.com/infraboard/mcube/v2/ioc/server"
99

10-
// 应用metric
1110
_ "github.com/infraboard/mcube/v2/ioc/apps/apidoc/restful"
1211
_ "github.com/infraboard/mcube/v2/ioc/apps/health/restful"
1312
_ "github.com/infraboard/mcube/v2/ioc/apps/metric/restful"
13+
_ "github.com/infraboard/mcube/v2/ioc/config/cors"
1414
)
1515

1616
func main() {

ioc/config/cors/cors.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ import (
1111
func init() {
1212
ioc.Config().Registry(&CORS{
1313
Enabled: true,
14-
AllowedHeaders: []string{"*"},
15-
AllowedDomains: []string{"*"},
14+
AllowedHeaders: []string{".*"},
15+
AllowedDomains: []string{".*"},
1616
AllowedMethods: []string{"HEAD", "OPTIONS", "GET", "POST", "PUT", "PATCH", "DELETE"},
1717
})
1818
}
1919

2020
type CORS struct {
2121
ioc.ObjectImpl
2222

23-
Enabled bool `toml:"enabled" json:"enabled" yaml:"enabled" env:"CORS_ENABLED"`
24-
AllowedHeaders []string `json:"cors_allowed_headers" yaml:"cors_allowed_headers" toml:"cors_allowed_headers" env:"CORS_ALLOWED_HEADERS" envSeparator:","`
25-
AllowedDomains []string `json:"cors_allowed_domains" yaml:"cors_allowed_domains" toml:"cors_allowed_domains" env:"CORS_ALLOWED_DOMAINS" envSeparator:","`
26-
AllowedMethods []string `json:"cors_allowed_methods" yaml:"cors_allowed_methods" toml:"cors_allowed_methods" env:"CORS_ALLOWED_METHODS" envSeparator:","`
23+
Enabled bool `toml:"enabled" json:"enabled" yaml:"enabled" env:"HTTP_CORS_ENABLED"`
24+
AllowedHeaders []string `json:"cors_allowed_headers" yaml:"cors_allowed_headers" toml:"cors_allowed_headers" env:"HTTP_CORS_ALLOWED_HEADERS" envSeparator:","`
25+
AllowedDomains []string `json:"cors_allowed_domains" yaml:"cors_allowed_domains" toml:"cors_allowed_domains" env:"HTTP_CORS_ALLOWED_DOMAINS" envSeparator:","`
26+
AllowedMethods []string `json:"cors_allowed_methods" yaml:"cors_allowed_methods" toml:"cors_allowed_methods" env:"HTTP_CORS_ALLOWED_METHODS" envSeparator:","`
2727
}
2828

2929
func (m *CORS) Name() string {

ioc/config/http/http.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,33 @@ type Http struct {
4242
ioc.ObjectImpl
4343

4444
// 是否开启HTTP Server, 默认会根据是否有注册得有API对象来自动开启
45-
Enable *bool `json:"enable" yaml:"enable" toml:"enable" env:"ENABLE"`
45+
Enable *bool `json:"enable" yaml:"enable" toml:"enable" env:"HTTP_ENABLE"`
4646
// HTTP服务Host
47-
Host string `json:"host" yaml:"host" toml:"host" env:"HOST"`
47+
Host string `json:"host" yaml:"host" toml:"host" env:"HTTP_HOST"`
4848
// HTTP服务端口
49-
Port int `json:"port" yaml:"port" toml:"port" env:"PORT"`
49+
Port int `json:"port" yaml:"port" toml:"port" env:"HTTP_PORT"`
5050
// API接口前缀
51-
PathPrefix string `json:"path_prefix" yaml:"path_prefix" toml:"path_prefix" env:"PATH_PREFIX"`
51+
PathPrefix string `json:"path_prefix" yaml:"path_prefix" toml:"path_prefix" env:"HTTP_PATH_PREFIX"`
5252

5353
// 使用的http框架, 默认会根据当前注册的API对象,自动选择合适的框架
54-
WEB_FRAMEWORK WEB_FRAMEWORK `json:"web_framework" yaml:"web_framework" toml:"web_framework" env:"WEB_FRAMEWORK"`
54+
WEB_FRAMEWORK WEB_FRAMEWORK `json:"web_framework" yaml:"web_framework" toml:"web_framework" env:"HTTP_WEB_FRAMEWORK"`
5555

5656
// HTTP服务器参数
5757
// HTTP Header读取超时时间
58-
ReadHeaderTimeoutSecond int `json:"read_header_timeout" yaml:"read_header_timeout" toml:"read_header_timeout" env:"READ_HEADER_TIMEOUT"`
58+
ReadHeaderTimeoutSecond int `json:"read_header_timeout" yaml:"read_header_timeout" toml:"read_header_timeout" env:"HTTP_READ_HEADER_TIMEOUT"`
5959
// 读取HTTP整个请求时的参数
60-
ReadTimeoutSecond int `json:"read_timeout" yaml:"read_timeout" toml:"read_timeout" env:"READ_TIMEOUT"`
60+
ReadTimeoutSecond int `json:"read_timeout" yaml:"read_timeout" toml:"read_timeout" env:"HTTP_READ_TIMEOUT"`
6161
// 响应超时时间
62-
WriteTimeoutSecond int `json:"write_timeout" yaml:"write_timeout" toml:"write_timeout" env:"WRITE_TIMEOUT"`
62+
WriteTimeoutSecond int `json:"write_timeout" yaml:"write_timeout" toml:"write_timeout" env:"HTTP_WRITE_TIMEOUT"`
6363
// 启用了KeepAlive时 复用TCP链接的超时时间
64-
IdleTimeoutSecond int `json:"idle_timeout" yaml:"idle_timeout" toml:"idle_timeout" env:"IDLE_TIMEOUT"`
64+
IdleTimeoutSecond int `json:"idle_timeout" yaml:"idle_timeout" toml:"idle_timeout" env:"HTTP_IDLE_TIMEOUT"`
6565
// header最大大小
66-
MaxHeaderSize string `json:"max_header_size" yaml:"max_header_size" toml:"max_header_size" env:"MAX_HEADER_SIZE"`
66+
MaxHeaderSize string `json:"max_header_size" yaml:"max_header_size" toml:"max_header_size" env:"HTTP_MAX_HEADER_SIZE"`
6767

6868
// 开启Trace
69-
EnableTrace bool `toml:"enable_trace" json:"enable_trace" yaml:"enable_trace" env:"ENABLE_TRACE"`
69+
EnableTrace bool `toml:"enable_trace" json:"enable_trace" yaml:"enable_trace" env:"HTTP_ENABLE_TRACE"`
70+
// 开启Trace
71+
Debug bool `toml:"debug" json:"debug" yaml:"debug" env:"HTTP_DEBUG"`
7072

7173
// 解析后的数据
7274
maxHeaderBytes uint64

ioc/config/http/restful.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ func (b *GoRestfulRouterBuilder) Build() (http.Handler, error) {
3131
r.Filter(filter)
3232
}
3333

34+
// 开启Debug
35+
if Get().Debug {
36+
restful.EnableTracing(true)
37+
}
38+
3439
// 装载Ioc路由之前
3540
for _, fn := range b.Before {
3641
fn(r)

0 commit comments

Comments
 (0)