Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Added WithHTTPClient option and set default http client on load
Browse files Browse the repository at this point in the history
  • Loading branch information
icellan committed Apr 19, 2022
1 parent 0045278 commit 2d068f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 0 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package bux

import (
"context"
"net/http"
"time"

"github.com/BuxOrg/bux/cachestore"
Expand Down Expand Up @@ -289,11 +288,6 @@ func (c *Client) Datastore() datastore.ClientInterface {

// HTTPClient will return the http interface to use in the client
func (c *Client) HTTPClient() HTTPInterface {
if c.options.httpClient == nil {
c.options.httpClient = &http.Client{
Timeout: defaultHTTPTimeout,
}
}
return c.options.httpClient
}

Expand Down
12 changes: 12 additions & 0 deletions client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bux
import (
"context"
"database/sql"
"net/http"
"strings"
"time"

Expand Down Expand Up @@ -63,6 +64,10 @@ func defaultClientOptions() *clientOptions {
options: []datastore.ClientOps{},
},

httpClient: &http.Client{
Timeout: defaultHTTPTimeout,
},

// Blank model options (use the Base models)
models: &modelOptions{
modelNames: modelNames(BaseModels...),
Expand Down Expand Up @@ -261,6 +266,13 @@ func WithImportBlockHeaders(blockHeadersZipFileURL string) ClientOps {
}
}

// WithHTTPClient will set the custom http interface
func WithHTTPClient(httpClient HTTPInterface) ClientOps {
return func(c *clientOptions) {
c.httpClient = httpClient
}
}

// WithLogger will set the custom logger interface
func WithLogger(customLogger logger.Interface) ClientOps {
return func(c *clientOptions) {
Expand Down

0 comments on commit 2d068f7

Please sign in to comment.