From 0e49559d0effb845c8392e00a3b860464ed88002 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sun, 2 Jan 2022 03:05:14 +0700 Subject: lib/http: refactoring NewClient to accept single struct Previously, the NewClient function accept three parameters: serverURL, http.Header, and insecure. If we want to add another parameter, for example timeout it will cause changes on the function signature. To prevent this changes in the future, we change it now. The NewClient now accept single struct. While at it, we add option to set Timeout. The Timeout affect the http Transport Timeout and TLSHandshakeTimeout. The field is optional, if not set it will set to 10 seconds. --- lib/http/example_server_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/http/example_server_test.go') diff --git a/lib/http/example_server_test.go b/lib/http/example_server_test.go index 2c886f27..aad952aa 100644 --- a/lib/http/example_server_test.go +++ b/lib/http/example_server_test.go @@ -60,7 +60,10 @@ func ExampleServer_customHTTPStatusCode() { // Wait for the server fully started. time.Sleep(1 * time.Second) - client := NewClient("http://127.0.0.1:8123", nil, false) + clientOpts := &ClientOptions{ + ServerUrl: "http://127.0.0.1:8123", + } + client := NewClient(clientOpts) httpRes, resBody, err := client.PostJSON(epCustom.Path, nil, nil) if err != nil { -- cgit v1.3-5-g9baa