您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021
  1. package transports
  2. import (
  3. "context"
  4. "encoding/json"
  5. "job_risk_third/internal/proto"
  6. "net/http"
  7. )
  8. //自定义一个解码error函数
  9. func MyErrorEncoder(_ context.Context, err error, w http.ResponseWriter) {
  10. res := proto.BaseResponse{
  11. RespCode: 500,
  12. RespMsg: err.Error(),
  13. }
  14. contentType := "application/json,charset=utf-8"
  15. w.Header().Set("content-type", contentType)
  16. w.WriteHeader(200)
  17. body, _ := json.Marshal(res)
  18. w.Write(body)
  19. }