go-zero通用的api 让你不需要写api服务
详细代码 handler.go
package zeroapi
func (h *Handler) defaultResponseHandler(in proto.Message) (code int, msg string, data interface{}) {
if in == nil {
return 0, "", nil
} else {
message, ok := in.(*dynamic.Message)
if ok {
if cod, exist := protoMessageValue(message, "errCode", 0); exist {
code = int(InterfaceToInt64(cod))
}
if failedReason, exist := protoMessageValue(message, "failedReason", ""); exist && failedReason != "" {
msg = failedReason.(string)
if code == 0 {
code = -1
}
}
data = in
return
}
return 0, "", in
}
}
详细代码 requestparser.go
_ = dm.TrySetFieldByName("ip", r.Header.Get("X-Real-IP"))