|
- package transports
-
- import (
- "context"
- "encoding/json"
- "job_risk_third/internal/proto"
- "net/http"
- )
-
- //自定义一个解码error函数
- func MyErrorEncoder(_ context.Context, err error, w http.ResponseWriter) {
- res := proto.BaseResponse{
- RespCode: 500,
- RespMsg: err.Error(),
- }
- contentType := "application/json,charset=utf-8"
- w.Header().Set("content-type", contentType)
- w.WriteHeader(200)
- body, _ := json.Marshal(res)
- w.Write(body)
- }
|