package api import ( "compress/gzip" "fmt" "io/ioutil" "net/http" "gitee.com/xuyiping_admin/pkg/xerr" "github.com/gin-gonic/gin" ) func Health(c *gin.Context) { c.String(http.StatusOK, ":)") } func Handle404(c *gin.Context) { c.String(http.StatusNotFound, "404 NotFound") } func dumpPerfEventBody(c *gin.Context) ([]byte, error) { if c.ContentType() != "application/octet-stream" { return nil, fmt.Errorf("invalid Content-Type: %s ", c.ContentType()) } if c.GetHeader("Content-Encoding") != "gzip" { return nil, fmt.Errorf("invalid Content-Encoding: %s ", c.GetHeader("Content-Encoding")) } if c.Request.Body == nil || int(c.Request.ContentLength) < 1 { return nil, fmt.Errorf("invalid body: %v ", int(c.Request.ContentLength)) } reader, err := gzip.NewReader(c.Request.Body) if err != nil { return nil, xerr.WithStack(err) } defer reader.Close() return ioutil.ReadAll(reader) } func Hello(c *gin.Context) { c.String(http.StatusOK, "hello world!") }