Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
Make client configurable (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
eculver authored Mar 22, 2021
1 parent 20e8a33 commit b93e6ff
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,36 @@ type Client struct {
Logger *log.Logger
}

// ClientOption modifies fields on a Client
type ClientOption func(c *Client)

// NewClient returns a Client pointer
func NewClient() *Client {
func NewClient(opts ...ClientOption) *Client {
baseURL, _ := url.Parse("https://app.opslevel.com")
return &Client{
client := &Client{
baseURL: baseURL,
httpClient: &http.Client{},
Logger: log.StandardLogger(),
}
for _, o := range opts {
o(client)
}
return client
}

// WithBaseURL modifies the Client baseURL.
func WithBaseURL(baseURL string) ClientOption {
return func(c *Client) {
bu, _ := url.Parse(baseURL)
c.baseURL = bu
}
}

// WithHTTPClient modifies the Client http.Client.
func WithHTTPClient(hc *http.Client) ClientOption {
return func(c *Client) {
c.httpClient = hc
}
}

func (c *Client) do(method string, path string, body io.Reader, recv interface{}) error {
Expand Down

0 comments on commit b93e6ff

Please sign in to comment.