From 0b2e22212435e08fccb4b7e89f49c1a8a2c17868 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 4 Oct 2024 20:31:38 -0400 Subject: [PATCH] refactor: remove extraneous Post webclient flow, use Do instead --- webclient/client_test.go | 5 ----- webclient/main.go | 5 ++--- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/webclient/client_test.go b/webclient/client_test.go index a8b4719..f1afd33 100644 --- a/webclient/client_test.go +++ b/webclient/client_test.go @@ -21,11 +21,6 @@ type DummyHttpClient struct { 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) { d.requests = append(d.requests, RecordedRequest{method: request.Method, url: request.URL.String(), contentType: "", data: request.Body}) return nil, nil diff --git a/webclient/main.go b/webclient/main.go index 74f6b0c..76452aa 100644 --- a/webclient/main.go +++ b/webclient/main.go @@ -4,14 +4,12 @@ import ( "bytes" "encoding/json" "fmt" - "io" "net/http" daemon "spud/daemon" service_definition "spud/service_definition" ) type HttpClient interface { - Post(string, string, io.Reader) (*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) - _, 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 }