| 123456789101112131415161718192021222324252627282930313233343536373839 | 
							- package handler
 
- import (
 
- 	"compress/gzip"
 
- 	"fmt"
 
- 	"io/ioutil"
 
- 	"kpt-tmr-group/pkg/xerr"
 
- 	"net/http"
 
- 	"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)
 
- }
 
 
  |