package subconfigs import ( "fmt" "git.x2erp.com/qdy/go-base/config/core" ) // HTTPConfig HTTP客户端配置 type HTTPConfig struct { core.BaseConfig Timeout int `yaml:"timeout" desc:"请求超时时间(秒)"` MaxIdleConns int `yaml:"max_idle_conns" desc:"最大空闲连接数"` MaxIdleConnsPerHost int `yaml:"max_idle_conns_per_host" desc:"每个主机的最大空闲连接数"` IdleConnTimeout int `yaml:"idle_conn_timeout" desc:"空闲连接超时时间(秒)"` MaxConnsPerHost int `yaml:"max_conns_per_host" desc:"每个主机的最大连接数"` DisableCompression bool `yaml:"disable_compression" desc:"是否禁用压缩"` DisableKeepAlives bool `yaml:"disable_keep_alives" desc:"是否禁用长连接"` } func (c *HTTPConfig) Description() string { return "调用其他api的http服务配置" } func NewHTTPConfig() *HTTPConfig { return &HTTPConfig{} } func (c *HTTPConfig) SetDefaults() { c.Timeout = 30 c.MaxIdleConns = 100 c.MaxIdleConnsPerHost = 10 c.IdleConnTimeout = 90 } func (c *HTTPConfig) Load(data map[string]interface{}) error { return c.LoadFromYAML(data, c) } func (c *HTTPConfig) Validate() error { if c.Timeout <= 0 { return fmt.Errorf("http timeout must be positive") } return nil } func (c *HTTPConfig) IsConfigured() bool { return c.Timeout > 0 } // 自动注册 func init() { core.Register("http", &HTTPConfig{}) }