response.go 691 B

1234567891011121314151617181920212223242526272829303132333435
  1. package app
  2. import (
  3. "dsbqj-admin/pkg/e"
  4. "dsbqj-admin/pkg/util"
  5. "os"
  6. "github.com/goccy/go-json"
  7. )
  8. type Response struct {
  9. Code int `json:"code"`
  10. Msg string `json:"msg"`
  11. Data interface{} `json:"data"`
  12. }
  13. func encode(data interface{}) interface{} {
  14. if os.Getenv("NAME") == "admin" && os.Getenv("DISABLE_RESPONSE_ENCRYPT") != "true" {
  15. buf, _ := json.Marshal(data)
  16. return util.EncryptDES_ECB(buf, os.Getenv("CRYPRO_SECRET"))
  17. }
  18. return data
  19. }
  20. // Response setting gin.JSON
  21. func (g *Gin) Response(httpCode, errCode int, data interface{}) {
  22. g.C.JSON(httpCode, Response{
  23. Code: errCode,
  24. Msg: e.GetMsg(errCode),
  25. Data: encode(data),
  26. // Data: data,
  27. })
  28. return
  29. }