response.go 475 B

123456789101112131415161718192021222324
  1. package model
  2. import (
  3. "encoding/json"
  4. "go-common/library/ecode"
  5. )
  6. // Response .
  7. type Response struct {
  8. Code int `json:"code"`
  9. Message string `json:"message"`
  10. Data map[string]interface{} `json:"data"`
  11. }
  12. // Message .
  13. func Message(raw map[string]interface{}, e error) (bs []byte) {
  14. res := &Response{
  15. Code: ecode.Cause(e).Code(),
  16. Message: ecode.Cause(e).Message(),
  17. Data: raw,
  18. }
  19. bs, _ = json.Marshal(res)
  20. return
  21. }