default.go 989 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package api
  2. import (
  3. "compress/gzip"
  4. "fmt"
  5. "io/ioutil"
  6. "net/http"
  7. "gitee.com/xuyiping_admin/pkg/xerr"
  8. "github.com/gin-gonic/gin"
  9. )
  10. func Health(c *gin.Context) {
  11. c.String(http.StatusOK, ":)")
  12. }
  13. func Handle404(c *gin.Context) {
  14. c.String(http.StatusNotFound, "404 NotFound")
  15. }
  16. func dumpPerfEventBody(c *gin.Context) ([]byte, error) {
  17. if c.ContentType() != "application/octet-stream" {
  18. return nil, fmt.Errorf("invalid Content-Type: %s ", c.ContentType())
  19. }
  20. if c.GetHeader("Content-Encoding") != "gzip" {
  21. return nil, fmt.Errorf("invalid Content-Encoding: %s ", c.GetHeader("Content-Encoding"))
  22. }
  23. if c.Request.Body == nil || int(c.Request.ContentLength) < 1 {
  24. return nil, fmt.Errorf("invalid body: %v ", int(c.Request.ContentLength))
  25. }
  26. reader, err := gzip.NewReader(c.Request.Body)
  27. if err != nil {
  28. return nil, xerr.WithStack(err)
  29. }
  30. defer reader.Close()
  31. return ioutil.ReadAll(reader)
  32. }
  33. func Hello(c *gin.Context) {
  34. c.String(http.StatusOK, "hello world!")
  35. }