示例#1
0
文件: router.go 项目: philipz/scope
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)
	}
}
示例#2
0
文件: router.go 项目: barravi/scope
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)
	}
}