diff options
Diffstat (limited to '')
-rw-r--r-- | pkg/helpers/json.go (renamed from cmd/tfstated/helpers.go) | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/cmd/tfstated/helpers.go b/pkg/helpers/json.go index 33e14a4..664a984 100644 --- a/cmd/tfstated/helpers.go +++ b/pkg/helpers/json.go @@ -1,4 +1,4 @@ -package main +package helpers import ( "encoding/json" @@ -7,14 +7,14 @@ import ( "net/http" ) -func decode(r *http.Request, data any) error { +func Decode(r *http.Request, data any) error { if err := json.NewDecoder(r.Body).Decode(&data); err != nil { return fmt.Errorf("failed to decode json: %w", err) } return nil } -func encode(w http.ResponseWriter, status int, data any) error { +func Encode(w http.ResponseWriter, status int, data any) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(status) if err := json.NewEncoder(w).Encode(data); err != nil { @@ -23,14 +23,3 @@ func encode(w http.ResponseWriter, status int, data any) error { } return nil } - -func errorResponse(w http.ResponseWriter, status int, err error) error { - type errorResponse struct { - Msg string `json:"msg"` - Status int `json:"status"` - } - return encode(w, status, &errorResponse{ - Msg: fmt.Sprintf("%+v", err), - Status: status, - }) -} |