Files
docker-cli/components/engine/api/server/httputils/httputils_write_json.go
Antonio Murdaca aaee5183a9 api/server/httputils: compile with go < 1.7
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
Upstream-commit: d1d505fa701bfe28a59afee8158994cf33ef043c
Component: engine
2016-10-04 12:01:49 +02:00

18 lines
395 B
Go

// +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)
}