github.com/olljanat/moby@v1.13.1/api/server/httputils/httputils_write_json_go16.go (about)

     1  // +build go1.6,!go1.7
     2  
     3  package httputils
     4  
     5  import (
     6  	"encoding/json"
     7  	"net/http"
     8  )
     9  
    10  // WriteJSON writes the value v to the http response stream as json with standard json encoding.
    11  func WriteJSON(w http.ResponseWriter, code int, v interface{}) error {
    12  	w.Header().Set("Content-Type", "application/json")
    13  	w.WriteHeader(code)
    14  	enc := json.NewEncoder(w)
    15  	return enc.Encode(v)
    16  }