mirror of
https://github.com/genuinetools/reg.git
synced 2024-09-12 06:11:03 -04:00
15 lines
436 B
Go
15 lines
436 B
Go
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)
|
|
}
|