| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package subconfigs
-
- import "fmt"
-
- // HTTPConfig HTTP客户端配置
- type HTTPConfig struct {
- BaseConfig
- Timeout int `yaml:"timeout"`
- MaxIdleConns int `yaml:"max_idle_conns"`
- MaxIdleConnsPerHost int `yaml:"max_idle_conns_per_host"`
- IdleConnTimeout int `yaml:"idle_conn_timeout"`
- MaxConnsPerHost int `yaml:"max_conns_per_host"`
- DisableCompression bool `yaml:"disable_compression"`
- DisableKeepAlives bool `yaml:"disable_keep_alives"`
- }
-
- 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() {
- Register("http", &HTTPConfig{})
- }
|