From bd79de6e1ba9a1a82026b63d386a0132bd513a2f Mon Sep 17 00:00:00 2001 From: Dominik Mlasko Date: Mon, 28 Oct 2024 11:14:42 +0100 Subject: [PATCH] Add client WithTimeout and WithRetry --- client.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/client.go b/client.go index 6f10ecc..c8efbf5 100644 --- a/client.go +++ b/client.go @@ -78,6 +78,22 @@ func WithAdminEmailPassword22(email, password string) ClientOption { } } +// WithTimeout set the timeout for requests +func WithTimeout(timeout time.Duration) ClientOption { + return func(c *Client) { + c.client.SetTimeout(timeout) + } +} + +// WithRetry set the retry settings for requests (defaults: count=3, waitTime=3s, maxWaitTime=10s) +func WithRetry(count int, waitTime, maxWaitTime time.Duration) ClientOption { + return func(c *Client) { + c.client.SetRetryCount(count) + c.client.SetRetryWaitTime(waitTime) + c.client.SetRetryMaxWaitTime(maxWaitTime) + } +} + func WithAdminEmailPassword(email, password string) ClientOption { return func(c *Client) { c.authorizer = newAuthorizeEmailPassword(c.client, c.url+fmt.Sprintf("/api/collections/%s/auth-with-password", core.CollectionNameSuperusers), email, password)