diff --git a/client.go b/client.go index 45d2ef2e..07a7f126 100644 --- a/client.go +++ b/client.go @@ -77,7 +77,7 @@ var ( defaultAuthScheme = "Bearer" - hdrUserAgentValue = "go-resty/" + Version + " (https://github.com/go-resty/resty)" + hdrUserAgentValue = "go-resty/" + Version + " (https://resty.dev)" bufPool = &sync.Pool{New: func() any { return &bytes.Buffer{} }} ) @@ -1426,8 +1426,12 @@ func (c *Client) ProxyURL() *url.URL { // SetProxy method sets the Proxy URL and Port for the Resty client. // +// // HTTP/HTTPS proxy // client.SetProxy("http://proxyserver:8888") // +// // SOCKS5 Proxy +// client.SetProxy("socks5://127.0.0.1:1080") +// // OR you could also set Proxy via environment variable, refer to [http.ProxyFromEnvironment] func (c *Client) SetProxy(proxyURL string) *Client { transport, err := c.HTTPTransport() diff --git a/client_test.go b/client_test.go index 42db25d4..94e4c9d9 100644 --- a/client_test.go +++ b/client_test.go @@ -275,6 +275,8 @@ func TestClientCACertificateFromStringErrorTls(t *testing.T) { // CustomRoundTripper2 just for test type CustomRoundTripper2 struct { + http.RoundTripper + TLSClientConfiger tlsConfig *tls.Config returnErr bool } diff --git a/load_balancer.go b/load_balancer.go index d344871f..760c41b7 100644 --- a/load_balancer.go +++ b/load_balancer.go @@ -101,7 +101,7 @@ type Host struct { // Default value is 5 MaxFailures int - state State + state HostState currentWeight int failedRequests int } @@ -114,16 +114,16 @@ func (h *Host) resetWeight(totalWeight int) { h.currentWeight -= totalWeight } -type State int +type HostState int // Host transition states const ( - StateInActive State = iota - StateActive + HostStateInActive HostState = iota + HostStateActive ) // HostStateChangeFunc type provides feedback on host state transitions -type HostStateChangeFunc func(baseURL string, from, to State) +type HostStateChangeFunc func(baseURL string, from, to HostState) // ErrNoActiveHost error returned when all hosts are inactive on the load balancer var ErrNoActiveHost = errors.New("resty: no active host") @@ -173,7 +173,7 @@ func (wrr *WeightedRoundRobin) Next() (string, error) { var best *Host total := 0 for _, h := range wrr.hosts { - if h.state == StateInActive { + if h.state == HostStateInActive { continue } @@ -205,9 +205,9 @@ func (wrr *WeightedRoundRobin) Feedback(f *RequestFeedback) { host.failedRequests++ } if host.failedRequests >= host.MaxFailures { - host.state = StateInActive + host.state = HostStateInActive if wrr.onStateChange != nil { - wrr.onStateChange(host.BaseURL, StateActive, StateInActive) + wrr.onStateChange(host.BaseURL, HostStateActive, HostStateInActive) } } break @@ -240,7 +240,7 @@ func (wrr *WeightedRoundRobin) Refresh(hosts ...*Host) error { } h.BaseURL = baseURL - h.state = StateActive + h.state = HostStateActive newTotalWeight += h.Weight // assign defaults if not provided @@ -274,12 +274,12 @@ func (wrr *WeightedRoundRobin) ticker() { for range wrr.tick.C { wrr.lock.Lock() for _, host := range wrr.hosts { - if host.state == StateInActive { - host.state = StateActive + if host.state == HostStateInActive { + host.state = HostStateActive host.failedRequests = 0 if wrr.onStateChange != nil { - wrr.onStateChange(host.BaseURL, StateInActive, StateActive) + wrr.onStateChange(host.BaseURL, HostStateInActive, HostStateActive) } } } diff --git a/load_balancer_test.go b/load_balancer_test.go index ad389948..3c307a2b 100644 --- a/load_balancer_test.go +++ b/load_balancer_test.go @@ -137,7 +137,7 @@ func TestWeightedRoundRobin(t *testing.T) { defer wrr.Close() var stateChangeCalled int32 - wrr.SetOnStateChange(func(baseURL string, from, to State) { + wrr.SetOnStateChange(func(baseURL string, from, to HostState) { atomic.AddInt32(&stateChangeCalled, 1) }) @@ -307,7 +307,7 @@ func TestSRVWeightedRoundRobin(t *testing.T) { assertNil(t, err) var stateChangeCalled int32 - srv.SetOnStateChange(func(baseURL string, from, to State) { + srv.SetOnStateChange(func(baseURL string, from, to HostState) { atomic.AddInt32(&stateChangeCalled, 1) })