mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 10:07:02 +00:00
[Rest Client] Use options for client.New (#463)
* adding in clientopts to the rest client Signed-off-by: Corey Aloia <corey.aloia@sap.com>
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/inbucket/inbucket/v3/pkg/rest/model"
|
||||
)
|
||||
@@ -18,15 +17,22 @@ type Client struct {
|
||||
|
||||
// New creates a new v1 REST API client given the base URL of an Inbucket server, ex:
|
||||
// "http://localhost:9000"
|
||||
func New(baseURL string) (*Client, error) {
|
||||
func New(baseURL string, opts ...Option) (*Client, error) {
|
||||
parsedURL, err := url.Parse(baseURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mergedOpts := getDefaultOptions()
|
||||
for _, opt := range opts {
|
||||
opt.apply(mergedOpts)
|
||||
}
|
||||
|
||||
c := &Client{
|
||||
restClient{
|
||||
client: &http.Client{
|
||||
Timeout: 30 * time.Second,
|
||||
Timeout: mergedOpts.timeout,
|
||||
Transport: mergedOpts.transport,
|
||||
},
|
||||
baseURL: parsedURL,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user