func mainHandler()

in forwarder/main.go [91:121]


func mainHandler(c echo.Context) error {
	r := c.Request()
	contentType := r.Header.Get("Content-Type")
	if contentType != "application/reports+json" {
		c.Echo().Logger.Errorf("Content-Type header is not application/reports+json: %v", r.Header)
		return c.String(http.StatusBadRequest, "Content-Type not supported. The Content-Type must be application/reports+json.")
	}

	data, err := io.ReadAll(r.Body)
	if err != nil {
		c.Echo().Logger.Errorf("error on reading data: %v", err)
	}
	c.Echo().Logger.Debug(string(data))
	if err := r.Body.Close(); err != nil {
		return err
	}

	var buf []map[string]interface{}
	err = json.Unmarshal(data, &buf)
	if err != nil {
		c.Echo().Logger.Errorf("error on parsing JSON: %v", err)
		return c.String(http.StatusInternalServerError, err.Error())
	}
	c.Echo().Logger.Debugf("queueing %v reports", len(buf))
	for _, b := range buf {
		// TODO(yoshifumi): Extrace values with keys and store them into SecurityReport
		reportCh <- mapToSecurityReport(c.Logger(), b)
	}

	return c.String(http.StatusNoContent, "OK")
}