-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: used a common http client for all the requests (#1201)
* refactor: used a common http client throughout for all the APIs * fix: handled goroutine exit * refactor: golangci-lint fix * refactor: defined http client fields in constants.go * refactor: defined http client as a field to HttpClient struct used as a method caller * refactor: revert InvokeFunctionWithTimeout() changes * refator: fixed tests * refactor: moved httpClient as the first parameter in api.go functions signature * refactor: removed exporting of client field from HttpClient struct * refactor: changed var to const keyword for http client constants
- Loading branch information
Showing
17 changed files
with
795 additions
and
723 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package client | ||
|
||
import ( | ||
"net/http" | ||
"razor/core/types" | ||
"time" | ||
) | ||
|
||
type HttpClient struct { | ||
client *http.Client | ||
} | ||
|
||
func NewHttpClient(config types.HttpClientConfig) *HttpClient { | ||
client := &http.Client{ | ||
Timeout: time.Duration(config.Timeout) * time.Second, | ||
Transport: &http.Transport{ | ||
MaxIdleConns: config.MaxIdleConnections, | ||
MaxIdleConnsPerHost: config.MaxIdleConnectionsPerHost, | ||
}, | ||
} | ||
return &HttpClient{client} | ||
} | ||
|
||
func (hc *HttpClient) Do(request *http.Request) (*http.Response, error) { | ||
return hc.client.Do(request) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.