icinga

Icinga2 API client in Go
git clone https://git.olowe.co/icinga
Log | Files | Refs | README | LICENSE

commit dad28b1a8f4f17dd47854db715221aa985024cef
parent 007a3d09eccd162b288c0584b68b0fdb83becf11
Author: Oliver Lowe <o@olowe.co>
Date:   Thu, 30 Dec 2021 18:50:08 +1100

set correct request Content-Type and Accept values in header

Diffstat:
Mhttp.go | 8+++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/http.go b/http.go @@ -1,7 +1,6 @@ package icinga import ( - "encoding/json" "io" "net/http" ) @@ -15,8 +14,15 @@ func newRequest(method, host, path string, body io.Reader) (*http.Request, error return nil, err } switch req.Method { + case http.MethodGet: + break + case http.MethodDelete: + req.Header.Set("Accept", "application/json") case http.MethodPost, http.MethodPut: + req.Header.Set("Accept", "application/json") req.Header.Set("Content-Type", "application/json") + default: + return nil, fmt.Errorf("new request: unsupported method %s", req.Method) } return req, nil }