Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions httpclient/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func (cfg ClientConfig) httpTransport() http.RoundTripper {
}

func NewApiClient(cfg ClientConfig) *ApiClient {
cfg.HTTPTimeout = time.Duration(orDefault(int(cfg.HTTPTimeout), int(30*time.Second)))
cfg.HTTPTimeout = time.Duration(orDefault(int64(cfg.HTTPTimeout), int64(30*time.Second)))
cfg.DebugTruncateBytes = orDefault(cfg.DebugTruncateBytes, 96)
cfg.RetryTimeout = time.Duration(orDefault(int(cfg.RetryTimeout), int(5*time.Minute)))
cfg.HTTPTimeout = time.Duration(orDefault(int(cfg.HTTPTimeout), int(30*time.Second)))
cfg.RetryTimeout = time.Duration(orDefault(int64(cfg.RetryTimeout), int64(5*time.Minute)))
cfg.HTTPTimeout = time.Duration(orDefault(int64(cfg.HTTPTimeout), int64(30*time.Second)))
if cfg.ErrorMapper == nil {
// default generic error mapper
cfg.ErrorMapper = DefaultErrorMapper
Expand Down Expand Up @@ -392,7 +392,11 @@ func (c *ApiClient) perform(
return resp, nil
}

func orDefault(configured, _default int) int {
type number interface {
~int | ~int64 | ~float64 | ~float32
}

func orDefault[T number](configured, _default T) T {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some other users of this function in the package. I opted for generic version so not to change other consumers.

if configured == 0 {
return _default
}
Expand Down
Loading