From f957be7f7963153975b8bb1a9a502177c836de51 Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 12 Mar 2025 13:50:52 +0000 Subject: [PATCH 1/2] added timeout changer to http client --- httpclient/timeouts.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 httpclient/timeouts.go diff --git a/httpclient/timeouts.go b/httpclient/timeouts.go new file mode 100644 index 0000000..2493352 --- /dev/null +++ b/httpclient/timeouts.go @@ -0,0 +1,15 @@ +package httpclient + +import ( + "sync" + "time" +) + +var mu sync.Mutex + +// Modifies the HTTP timeout time +func (c *Client) ModifyHttpTimeout(newTimeout time.Duration) { + mu.Lock() + defer mu.Unlock() + c.http.Timeout = newTimeout +} From 6008e7c92a156ba52638df20b02b9b88f2cc8dd6 Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 12 Mar 2025 13:57:58 +0000 Subject: [PATCH 2/2] Added reset function too --- httpclient/client.go | 4 +--- httpclient/timeouts.go | 9 ++++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/httpclient/client.go b/httpclient/client.go index 281052c..c301c52 100644 --- a/httpclient/client.go +++ b/httpclient/client.go @@ -17,7 +17,7 @@ import ( "go.uber.org/zap" ) -const DefaultTimeout time.Duration = 5 * time.Second +const DefaultTimeout time.Duration = 10 * time.Second // Master struct/object type Client struct { @@ -135,8 +135,6 @@ func (c *ClientConfig) Build() (*Client, error) { ) } - - client := &Client{ Integration: &c.Integration, http: &httpClient, diff --git a/httpclient/timeouts.go b/httpclient/timeouts.go index 2493352..c228797 100644 --- a/httpclient/timeouts.go +++ b/httpclient/timeouts.go @@ -7,9 +7,16 @@ import ( var mu sync.Mutex -// Modifies the HTTP timeout time +// Amends the HTTP timeout time func (c *Client) ModifyHttpTimeout(newTimeout time.Duration) { mu.Lock() defer mu.Unlock() c.http.Timeout = newTimeout } + +// Resets HTTP timeout time back to 10 seconds +func (c *Client) ResetTimeout() { + mu.Lock() + defer mu.Unlock() + c.http.Timeout = DefaultTimeout +}