func()

in plugins/receiver/http/nativcelog/receiver.go [100:134]


func (r *Receiver) httpHandler() http.Handler {
	h := http.HandlerFunc(func(rsp http.ResponseWriter, req *http.Request) {
		rsp.Header().Set("Content-Type", "application/json")
		b, err := io.ReadAll(req.Body)
		if err != nil {
			log.Logger.Errorf("get http body error: %v", err)
			response := &Response{Status: failing, Msg: err.Error()}
			ResponseWithJSON(rsp, response, http.StatusBadRequest)
			return
		}
		var data logging.LogData
		err = proto.Unmarshal(b, &data)
		if err != nil {
			response := &Response{Status: failing, Msg: err.Error()}
			ResponseWithJSON(rsp, response, http.StatusInternalServerError)
			return
		}
		e := &v1.SniffData{
			Name:      eventName,
			Timestamp: time.Now().UnixNano() / 1e6,
			Meta:      nil,
			Type:      v1.SniffType_Logging,
			Remote:    true,
			Data: &v1.SniffData_LogList{
				LogList: &v1.BatchLogList{
					Logs: [][]byte{b},
				},
			},
		}
		r.OutputChannel <- e
		response := &Response{Status: success, Msg: success}
		ResponseWithJSON(rsp, response, http.StatusOK)
	})
	return http.TimeoutHandler(h, time.Duration(r.Timeout)*time.Second, fmt.Sprintf("Exceeded configured timeout of %d seconds", r.Timeout))
}