1
0
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:
corey-aloia
2024-01-25 18:46:31 +01:00
committed by GitHub
parent 2d409bb2b1
commit b5ccd3da51
3 changed files with 91 additions and 5 deletions

View File

@@ -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,
},