common.go 653 B

12345678910111213141516171819202122232425262728293031
  1. package serializer
  2. // Response 基础序列化器
  3. type Response struct {
  4. Code int `json:"code"`
  5. Data interface{} `json:"data"`
  6. Msg string `json:"msg"`
  7. Error string `json:"error"`
  8. }
  9. // DataList 基础列表结构
  10. type DataList struct {
  11. Items interface{} `json:"items"`
  12. Total uint `json:"total"`
  13. }
  14. // TrackedErrorResponse 有追踪信息的错误响应
  15. type TrackedErrorResponse struct {
  16. Response
  17. TrackID string `json:"track_id"`
  18. }
  19. // BuildListResponse 列表构建器
  20. func BuildListResponse(items interface{}, total uint) Response {
  21. return Response{
  22. Data: DataList{
  23. Items: items,
  24. Total: total,
  25. },
  26. }
  27. }