diff options
| author | Sebastiaan van Stijn <github@gone.nl> | 2022-04-05 13:21:19 +0200 |
|---|---|---|
| committer | Sebastiaan van Stijn <github@gone.nl> | 2022-04-11 21:37:57 +0200 |
| commit | ff5f70e55f8cd303efbaee3eafda9dfe86a3da36 (patch) | |
| tree | 194611e79f1ca9f4b306f066e6fa8af9273a7f2a /api/server/httputils | |
| parent | 0c9ff0b45a70061d43655672b2e8227e1b51684f (diff) | |
| download | docker-ff5f70e55f8cd303efbaee3eafda9dfe86a3da36.tar.gz | |
api/server/httputils: move WriteJSON() together with ReadJSON()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Diffstat (limited to 'api/server/httputils')
| -rw-r--r-- | api/server/httputils/httputils.go | 9 | ||||
| -rw-r--r-- | api/server/httputils/httputils_write_json.go | 15 |
2 files changed, 9 insertions, 15 deletions
diff --git a/api/server/httputils/httputils.go b/api/server/httputils/httputils.go index 386695ca32..531cbde2b6 100644 --- a/api/server/httputils/httputils.go +++ b/api/server/httputils/httputils.go @@ -86,6 +86,15 @@ func ReadJSON(r *http.Request, out interface{}) error { return nil } +// WriteJSON writes the value v to the http response stream as json with standard json encoding. +func WriteJSON(w http.ResponseWriter, code int, v interface{}) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(code) + enc := json.NewEncoder(w) + enc.SetEscapeHTML(false) + return enc.Encode(v) +} + // ParseForm ensures the request form is parsed even with invalid content types. // If we don't do this, POST method without Content-type (even with empty body) will fail. func ParseForm(r *http.Request) error { diff --git a/api/server/httputils/httputils_write_json.go b/api/server/httputils/httputils_write_json.go deleted file mode 100644 index 148dd038b3..0000000000 --- a/api/server/httputils/httputils_write_json.go +++ /dev/null @@ -1,15 +0,0 @@ -package httputils // import "github.com/docker/docker/api/server/httputils" - -import ( - "encoding/json" - "net/http" -) - -// WriteJSON writes the value v to the http response stream as json with standard json encoding. -func WriteJSON(w http.ResponseWriter, code int, v interface{}) error { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(code) - enc := json.NewEncoder(w) - enc.SetEscapeHTML(false) - return enc.Encode(v) -} |
