feat(protocol): allow override of dial func
This commit is contained in:
@ -20,7 +20,9 @@ func (o *Operations) GetJSON(path string, dst any) error {
|
||||
var res *http.Response
|
||||
|
||||
url := o.getURL(path)
|
||||
res, err := http.Get(url)
|
||||
client := o.getHTTPClient()
|
||||
|
||||
res, err := client.Get(url)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
@ -50,6 +52,7 @@ func (o *Operations) GetJSON(path string, dst any) error {
|
||||
}
|
||||
|
||||
func (o *Operations) PostJSON(path string, data any, dst any) error {
|
||||
|
||||
var res *http.Response
|
||||
|
||||
var buf bytes.Buffer
|
||||
@ -60,7 +63,9 @@ func (o *Operations) PostJSON(path string, data any, dst any) error {
|
||||
}
|
||||
|
||||
url := o.getURL(path)
|
||||
res, err := http.Post(url, "application/json", &buf)
|
||||
client := o.getHTTPClient()
|
||||
|
||||
res, err := client.Post(url, "application/json", &buf)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
@ -89,6 +94,18 @@ func (o *Operations) PostJSON(path string, data any, dst any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Operations) getHTTPClient() *http.Client {
|
||||
o.getClientOnce.Do(func() {
|
||||
o.httpClient = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Dial: o.dial,
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
return o.httpClient
|
||||
}
|
||||
|
||||
func (o *Operations) PostBaseCoordinates(ctx context.Context, base *model.Base) (*model.Base, error) {
|
||||
var updated model.Base
|
||||
|
||||
|
Reference in New Issue
Block a user