Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"net/http"
"sync"
"sync/atomic"
)
Expand All @@ -17,6 +18,9 @@ type Client struct {
authMu sync.Mutex
authToken string
authTokenExp int64

httpClientMu sync.Mutex
httpClient_ *http.Client
}

func NewClient(ctx Context) *Client {
Expand Down
18 changes: 16 additions & 2 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,16 @@ func (c *Client) checkCriteria(token string, switcher *Switcher, showDetails boo
query.Set("showReason", strings.ToLower(strconvFormatBool(showDetails)))
query.Set("key", switcher.key)

entries := switcher.entries
if entries == nil {
entries = []criteriaEntry{}
}

response, err := c.doJSONRequest(
http.MethodPost,
endpoint+"?"+query.Encode(),
map[string]any{
"entry": switcher.entries,
"entry": entries,
},
map[string]string{
"Authorization": "Bearer " + token,
Expand Down Expand Up @@ -147,6 +152,13 @@ func (c *Client) doJSONRequest(method, endpoint string, payload any, headers map
}

func (c *Client) httpClient() *http.Client {
c.httpClientMu.Lock()
defer c.httpClientMu.Unlock()

if c.httpClient_ != nil {
return c.httpClient_
}

ctx := c.Context()
dialer := &net.Dialer{
Timeout: ctx.Options.Remote.ConnectTimeout,
Expand All @@ -162,10 +174,12 @@ func (c *Client) httpClient() *http.Client {
},
}

return &http.Client{
c.httpClient_ = &http.Client{
Transport: transport,
Timeout: requestTimeout(ctx.Options.Remote),
}

return c.httpClient_
}

func requestTimeout(options RemoteOptions) time.Duration {
Expand Down
Loading