From 09ba2760c1e285bb89544a23c3ed6fdc507a496e Mon Sep 17 00:00:00 2001 From: Johan Svensson Date: Tue, 18 May 2021 19:14:58 +0200 Subject: [PATCH 1/2] Check error before attempting to use request --- module.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/module.go b/module.go index 3e983cc..a2dafb5 100644 --- a/module.go +++ b/module.go @@ -81,12 +81,14 @@ func newModule(filename string) (*module, error) { } func (m *module) newRequest(baseURL, path string) (*http.Request, error) { - req, err := http.NewRequest( m.Request.Method, baseURL+path, bytes.NewBuffer([]byte(m.Request.Body)), ) + if err != nil { + return nil, err + } for _, h := range m.Request.Headers { parts := strings.SplitN(h, ":", 2) @@ -102,10 +104,6 @@ func (m *module) newRequest(baseURL, path string) (*http.Request, error) { req.Header.Set(k, v) } - if err != nil { - return nil, err - } - return req, nil } From a6757d6a394f93d10cfa6e9330dc1964b2bbc881 Mon Sep 17 00:00:00 2001 From: Johan Svensson Date: Tue, 18 May 2021 19:17:05 +0200 Subject: [PATCH 2/2] Don't use printf without formatting --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index b590e61..fb715df 100644 --- a/main.go +++ b/main.go @@ -24,7 +24,7 @@ func init() { "", } - fmt.Fprintf(os.Stderr, strings.Join(h, "\n")) + fmt.Fprint(os.Stderr, strings.Join(h, "\n")) } }