http.ResponseWriter
implements Write([]byte) (int, error)
. Therefore you can use it everywhere where a io.Writer
is required.
func handler(w http.ResponseWriter, r *http.Request) {
encoder := json.NewEncoder(w)
}
Here you can find some background information on how Go uses interfaces as a way to specify the behavior of an object.