PageModel.go 774 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package cloudserver
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "github.com/yuguorong/go/log"
  6. )
  7. type PageModel struct {
  8. Rows []interface{} `json:"rows"`
  9. Total int `json:"total"`
  10. }
  11. func (p *PageModel) ChangeData(resPoint interface{}) error {
  12. if len(p.Rows) == 0 {
  13. return nil
  14. }
  15. b, e := json.Marshal(p.Rows)
  16. log.Info("data", string(b))
  17. if e != nil {
  18. return e
  19. }
  20. e = json.Unmarshal(b, resPoint)
  21. return e
  22. }
  23. type CommonResp struct {
  24. Code int `json:"code"`
  25. Data interface{} `json:"data"`
  26. Msg string `json:"msg"`
  27. }
  28. func (c *CommonResp) ChangeData(resPoint interface{}) error {
  29. if c.Data == nil {
  30. return errors.New("data is empty")
  31. }
  32. b, e := json.Marshal(c.Data)
  33. if e != nil {
  34. return e
  35. }
  36. e = json.Unmarshal(b, resPoint)
  37. return e
  38. }