response.go 651 B

123456789101112131415161718192021222324252627282930313233343536
  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" {
  15. buf, _ := json.Marshal(data)
  16. return util.EncryptDES_ECB(buf, os.Getenv("CRYPRO_SECRET"))
  17. } else {
  18. return data
  19. }
  20. }
  21. // Response setting gin.JSON
  22. func (g *Gin) Response(httpCode, errCode int, data interface{}) {
  23. g.C.JSON(httpCode, Response{
  24. Code: errCode,
  25. Msg: e.GetMsg(errCode),
  26. Data: encode(data),
  27. // Data: data,
  28. })
  29. return
  30. }