Beispiel #1
0
func makeReportPostHandler(a xfer.Adder) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var rpt report.Report

		var reader io.ReadCloser
		defer func() { reader.Close() }()

		reader = r.Body
		var err error
		if strings.Contains(r.Header.Get("Content-Encoding"), "gzip") {
			reader, err = gzip.NewReader(r.Body)
			if err != nil {
				http.Error(w, err.Error(), http.StatusBadRequest)
				return
			}
		}

		if err := gob.NewDecoder(reader).Decode(&rpt); err != nil {
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}
		a.Add(rpt)
		w.WriteHeader(http.StatusOK)
	}
}
Beispiel #2
0
func makeReportPostHandler(a xfer.Adder) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var rpt report.Report
		if err := gob.NewDecoder(r.Body).Decode(&rpt); err != nil {
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}
		a.Add(rpt)
		w.WriteHeader(http.StatusOK)
	}
}