// WriteProtoResponse serializes msg to w. func WriteProtoResponse(w http.ResponseWriter, r *http.Request, msg proto.Message) error { w.Header().Set("Content-Type", "application/x-protobuf") cw := httpencoding.CompressData(w, r) defer cw.Close() rec, err := proto.Marshal(msg) if err != nil { return fmt.Errorf("error marshaling proto: %v", err) } _, err = cw.Write(rec) return err }
// WriteJSONResponse encodes v as JSON and writes it to w. func WriteJSONResponse(w http.ResponseWriter, r *http.Request, v interface{}) error { w.Header().Set("Content-Type", "application/json; charset=utf-8") cw := httpencoding.CompressData(w, r) defer cw.Close() return json.NewEncoder(cw).Encode(v) }