diff --git a/client.go b/client.go index 9fe75a0..254c52f 100644 --- a/client.go +++ b/client.go @@ -11,10 +11,9 @@ import ( "path/filepath" "strings" - "git.sr.ht/~jamesponddotco/httpx-go" "git.sr.ht/~jamesponddotco/xstd-go/xerrors" + "git.sr.ht/~jamesponddotco/xstd-go/xnet/xhttp" "git.sr.ht/~jamesponddotco/xstd-go/xstrings" - "golang.org/x/time/rate" ) const ( @@ -26,7 +25,7 @@ type ( // Client is the LanguageTool API client. Client struct { // httpc is the underlying HTTP client used by the API client. - httpc *httpx.Client + httpc *http.Client // cfg specifies the configuration used by the API client. cfg *Config @@ -45,12 +44,16 @@ func NewClient(cfg *Config) (*Client, error) { return nil, err } + retryPolicy := &xhttp.RetryPolicy{ + IsRetryable: xhttp.DefaultIsRetryable, + MaxRetries: cfg.MaxRetries, + MinRetryDelay: xhttp.DefaultMinRetryDelay, + MaxRetryDelay: xhttp.DefaultMaxRetryDelay, + } + return &Client{ - httpc: &httpx.Client{ - RateLimiter: rate.NewLimiter(rate.Limit(2), 1), - RetryPolicy: httpx.DefaultRetryPolicy(), - }, - cfg: cfg, + httpc: xhttp.NewRetryingClient(cfg.Timeout, retryPolicy, cfg.Logger), + cfg: cfg, }, nil } @@ -160,14 +163,14 @@ func (c *Client) Delete(ctx context.Context, path, filename string) (*Response, } // do performs an HTTP request using the underlying HTTP client. -func (c *Client) do(ctx context.Context, req *http.Request) (*Response, error) { - ret, err := c.httpc.Do(ctx, req) +func (c *Client) do(_ context.Context, req *http.Request) (*Response, error) { + ret, err := c.httpc.Do(req) if err != nil { return nil, fmt.Errorf("%w", err) } defer func() { - if err = httpx.DrainResponseBody(ret); err != nil { + if err = xhttp.DrainResponseBody(ret); err != nil { log.Fatal(err) } }() diff --git a/go.mod b/go.mod index 518e521..6fc515d 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( git.sr.ht/~jamesponddotco/httpx-go v0.0.0-20230427215504-7c26a7f028e7 - git.sr.ht/~jamesponddotco/xstd-go v0.0.0-20230709232003-22489c0e7382 + git.sr.ht/~jamesponddotco/xstd-go v0.7.1 golang.org/x/time v0.3.0 ) diff --git a/go.sum b/go.sum index ba9e314..95a48d5 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,10 @@ git.sr.ht/~jamesponddotco/recache-go v1.0.1 h1:O9S7SdGyMh4mD+Vom0WOkY45EhJJHDRBl git.sr.ht/~jamesponddotco/recache-go v1.0.1/go.mod h1:oF6LkAuwZYQqHe8+G/4hP9ZSNyDjAk6J8qhuy44wXw0= git.sr.ht/~jamesponddotco/xstd-go v0.0.0-20230709232003-22489c0e7382 h1:3LjkxT6zVDvIlaOc5riiRAnAKVgpTWHxWgmzpzOuR8A= git.sr.ht/~jamesponddotco/xstd-go v0.0.0-20230709232003-22489c0e7382/go.mod h1:0tqdK5/MZYSPxAiwtG4LlVfdQ+iaFoksU/FTIGQ/v/Y= +git.sr.ht/~jamesponddotco/xstd-go v0.7.0 h1:fwcjXnmTzEsrHXPXMvFFyz+6d/xyDSNShbyKBdXz0eM= +git.sr.ht/~jamesponddotco/xstd-go v0.7.0/go.mod h1:L0SjmhDqcj/gR7oeNof+ed6l9VPk6oHPeNQSoaFBRFk= +git.sr.ht/~jamesponddotco/xstd-go v0.7.1 h1:MqkIWlzLwBOVLf9W2qLVF5m/QnJzuNiKA/4P+ditvnk= +git.sr.ht/~jamesponddotco/xstd-go v0.7.1/go.mod h1:L0SjmhDqcj/gR7oeNof+ed6l9VPk6oHPeNQSoaFBRFk= golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ= golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=