-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
config.go
73 lines (64 loc) · 2.38 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
73
package client
import (
"fmt"
"time"
"github.com/plgd-dev/hub/v2/pkg/security/certManager/client"
)
type Config struct {
// MaxIdleConns controls the maximum number of idle (keep-alive)
// connections across all hosts. Zero means no limit.
MaxIdleConns int `yaml:"maxIdleConns" json:"maxIdleConns"`
// MaxConnsPerHost optionally limits the total number of
// connections per host, including connections in the dialing,
// active, and idle states. On limit violation, dials will block.
//
// Zero means no limit.
MaxConnsPerHost int `yaml:"maxConnsPerHost" json:"maxConnsPerHost"`
// MaxIdleConnsPerHost, if non-zero, controls the maximum idle
// (keep-alive) connections to keep per-host. If zero,
// DefaultMaxIdleConnsPerHost is used.
MaxIdleConnsPerHost int `yaml:"maxIdleConnsPerHost" json:"maxIdleConnsPerHost"`
// IdleConnTimeout is the maximum amount of time an idle
// (keep-alive) connection will remain idle before closing
// itself.
// Zero means no limit.
IdleConnTimeout time.Duration `yaml:"idleConnTimeout" json:"idleConnTimeout"`
// Timeout specifies a time limit for requests made by this
// Client. The timeout includes connection time, any
// redirects, and reading the response body. The timer remains
// running after Get, Head, Post, or Do return and will
// interrupt reading of the Response.Body.
//
// A Timeout of zero means no timeout.
//
// The Client cancels requests to the underlying Transport
// as if the Request's Context ended.
//
// For compatibility, the Client will also use the deprecated
// CancelRequest method on Transport if found. New
// RoundTripper implementations should use the Request's Context
// for cancellation instead of implementing CancelRequest.
Timeout time.Duration `yaml:"timeout" json:"timeout"`
TLS client.Config `yaml:"tls" json:"tls"`
}
func (c *Config) Validate() error {
if c.MaxIdleConns < 0 {
return fmt.Errorf("maxIdleConns('%v')", c.MaxIdleConns)
}
if c.MaxConnsPerHost < 0 {
return fmt.Errorf("maxConnsPerHost('%v')", c.MaxConnsPerHost)
}
if c.MaxIdleConnsPerHost < 0 {
return fmt.Errorf("maxIdleConnsPerHost('%v')", c.MaxIdleConnsPerHost)
}
if c.IdleConnTimeout < 0 {
return fmt.Errorf("idleConnTimeout('%v')", c.IdleConnTimeout)
}
if c.Timeout < 0 {
return fmt.Errorf("timeout('%v')", c.Timeout)
}
if err := c.TLS.Validate(); err != nil {
return fmt.Errorf("tls.%w", err)
}
return nil
}