mirror of
https://github.com/moby/moby.git
synced 2025-07-29 07:21:35 +03:00
api/server/httputils: compile with go < 1.7
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
17
api/server/httputils/httputils_write_json.go
Normal file
17
api/server/httputils/httputils_write_json.go
Normal file
@ -0,0 +1,17 @@
|
||||
// +build go1.7
|
||||
|
||||
package 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)
|
||||
}
|
Reference in New Issue
Block a user