From dba7aa16a4df5e89c2aea5cec1d07609f468de82 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sat, 12 Jul 2025 17:49:23 +0700 Subject: all: add option Timeout to Client The Timeout option affect how long the client wait for connect and waiting for response. --- client.go | 1 + client_options.go | 4 ++++ testdata/client_options_test.txt | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index c518a15..f72415d 100644 --- a/client.go +++ b/client.go @@ -55,6 +55,7 @@ func NewClient(opts ClientOptions) (cl *Client, err error) { logp = `NewClient` httpcOpts = libhttp.ClientOptions{ ServerUrl: opts.ServerUrl, + Timeout: opts.Timeout, } ) diff --git a/client_options.go b/client_options.go index fa6ad1c..2bdbffe 100644 --- a/client_options.go +++ b/client_options.go @@ -7,6 +7,7 @@ import ( "fmt" "net/url" "os" + "time" "github.com/shuLhan/share/lib/ini" ) @@ -33,6 +34,9 @@ type ClientOptions struct { // DisburseUserID user ID for disbursement request. DisburseUserID int64 `ini:"duitku::disburse_user_id"` + + // Timeout for connection and response. + Timeout time.Duration } // LoadClientOptions load ClientOptions from file. diff --git a/testdata/client_options_test.txt b/testdata/client_options_test.txt index 5d4d34e..aa5106b 100644 --- a/testdata/client_options_test.txt +++ b/testdata/client_options_test.txt @@ -35,5 +35,6 @@ api_key = 1ndom4r3t }, "DisburseApiKey": "abcd", "DisburseEmail": "my@company.com", - "DisburseUserID": 1111 + "DisburseUserID": 1111, + "Timeout": 0 } -- cgit v1.3