1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/api/server/httputils/httputils_write_json.go
Boaz Shuster 6bfd0f6b5d Remove Go 1.6 code from moby
Signed-off-by: Boaz Shuster <ripcurld.github@gmail.com>
2017-06-19 15:59:00 +03:00

15 lines
378 B
Go

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