refactor: remove extraneous Post webclient flow, use Do instead

This commit is contained in:
Marc 2024-10-04 20:31:38 -04:00
parent 4cad5e875d
commit 0b2e222124
Signed by: marc
GPG key ID: 048E042F22B5DC79
2 changed files with 2 additions and 8 deletions

View file

@ -21,11 +21,6 @@ type DummyHttpClient struct {
requests []RecordedRequest requests []RecordedRequest
} }
func (d *DummyHttpClient) Post(url string, contentType string, data io.Reader) (*http.Response, error) {
d.requests = append(d.requests, RecordedRequest{method: http.MethodPost, url: url, contentType: contentType, data: data})
return nil, nil
}
func (d *DummyHttpClient) Do(request *http.Request) (*http.Response, error) { func (d *DummyHttpClient) Do(request *http.Request) (*http.Response, error) {
d.requests = append(d.requests, RecordedRequest{method: request.Method, url: request.URL.String(), contentType: "", data: request.Body}) d.requests = append(d.requests, RecordedRequest{method: request.Method, url: request.URL.String(), contentType: "", data: request.Body})
return nil, nil return nil, nil

View file

@ -4,14 +4,12 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"net/http" "net/http"
daemon "spud/daemon" daemon "spud/daemon"
service_definition "spud/service_definition" service_definition "spud/service_definition"
) )
type HttpClient interface { type HttpClient interface {
Post(string, string, io.Reader) (*http.Response, error)
Do(*http.Request) (*http.Response, error) Do(*http.Request) (*http.Response, error)
} }
@ -40,7 +38,8 @@ func (c WebClient) CreateService(def service_definition.ServiceDefinition) error
serializedPayload, _ := json.Marshal(payload) serializedPayload, _ := json.Marshal(payload)
_, e := c.httpClient.Post(c.getBaseUrl()+"/service/", "application/json", bytes.NewBuffer(serializedPayload)) req, _ := http.NewRequest(http.MethodPost, c.getBaseUrl()+"/service/", bytes.NewBuffer(serializedPayload))
_, e := c.httpClient.Do(req)
return e return e
} }