reply.go 906 B

123456789101112131415161718192021222324252627282930313233343536
  1. package reply
  2. type SuccessReply struct {
  3. Code int32 `json:"code"`
  4. Message string `json:"message"`
  5. Data interface{} `json:"data"`
  6. }
  7. //func SetContentType(w http.ResponseWriter, contentType string) {
  8. // if contentType == "" {
  9. // return
  10. // }
  11. // w.Header().Set("Content-Type", contentType)
  12. //}
  13. //
  14. //func ErrorReturn(err error, w http.ResponseWriter, r *http.Request, h http2.HandleOptions) {
  15. // errStatus := errors.FromError(err)
  16. // if errStatus != nil {
  17. // if errStatus.Reason != "" {
  18. // fail := &SuccessReply{
  19. // Code: errStatus.GRPCStatus().Proto().Code,
  20. // Message: errStatus.GRPCStatus().Message(),
  21. // }
  22. // var obj interface{}
  23. // json.Unmarshal([]byte(errors.Reason(err)), &obj)
  24. // fail.Data = obj
  25. // w.WriteHeader(400)
  26. // if err = h.Encode(w, r, fail); err != nil {
  27. // h.Error(w, r, err)
  28. // }
  29. // return
  30. // }
  31. // }
  32. // h.Error(w, r, err)
  33. // return
  34. //}