Comments (12)
有两种办法可以实现:
第一种:使用脚本替换现有gin.pb里的 app.Success
同时替换import的包
第二种:参考现有的插件实现一个自己的扩展,参考:https://github.com/go-eagle/eagle/tree/master/cmd/protoc-gen-go-gin
,然后修改makefile,改为自己的插件即可。
以上供参考。
from eagle.
why tag me?
from eagle.
why tag me?
sorry for that. @ prompts a list of names, I thought it was a related member
from eagle.
@qloog 我找到问题了,生成的_gin.pb文件中处理错误的方法中定义的接口iCode 需要实现以下三个接口:
HTTPCode() int
Message() string
Code() int
但是eagle的错误类型没有实现Message()&HTTPCode() 这两个方法,只有Msg() & Code()
可以给我个权限我来修复下这个问题
from eagle.
@SonderEASE 错误分两种,
一种是属于系统类的错误,比如404、参数错误、内部错误,
另一种是 业务内错误,这时可以返回具体的业务错误码,比如用户已存在:errcode.New(20100, "The user already exists.")
全部内容如下:
var (
// common errors
ErrSuccess = errcode.New(codes.OK, "Ok")
ErrInvalidArgument = errcode.New(codes.InvalidArgument, "Invalid argument")
ErrInternalError = errcode.New(codes.Internal, "Internal error")
ErrAccessDenied = errcode.New(codes.PermissionDenied, "Access denied")
ErrNotFound = errcode.New(codes.NotFound, "Not found")
// biz errors
ErrUserIsExist = errcode.New(20100, "The user already exists.")
)
如果有改进建议可以提交PR。
from eagle.
@SonderEASE 错误分两种, 一种是属于系统类的错误,比如404、参数错误、内部错误, 另一种是 业务内错误,这时可以返回具体的业务错误码,比如用户已存在:
errcode.New(20100, "The user already exists.")
全部内容如下:
var ( // common errors ErrSuccess = errcode.New(codes.OK, "Ok") ErrInvalidArgument = errcode.New(codes.InvalidArgument, "Invalid argument") ErrInternalError = errcode.New(codes.Internal, "Internal error") ErrAccessDenied = errcode.New(codes.PermissionDenied, "Access denied") ErrNotFound = errcode.New(codes.NotFound, "Not found") // biz errors ErrUserIsExist = errcode.New(20100, "The user already exists.") )
如果有改进建议可以提交PR。
这个我能理解, 问题是说这个错误类型,没有实现
HTTPCode() int
Message() string
这两个接口,而通过make生成的xxx_gin.pb.go文件中,解析错误的接口是
type iCode interface {
HTTPCode() int
Message() string
Code() int
}
因为没实现所以,errors.As(err, &c) 这个解析会失败。
from eagle.
这个interface iCode
是在哪里看到的?新版本应该是没有这个了。 @SonderEASE
from eagle.
这个interface
iCode
是在哪里看到的?新版本应该是没有这个了。 @SonderEASE
# generate http code
http:
protoc --proto_path=. \
--proto_path=./third_party \
--go_out=. --go_opt=paths=source_relative \
--go-gin_out=. --go-gin_opt=paths=source_relative \
$(API_PROTO_FILES)
这个make语句生成的,_gin.pb.go文件中都有iCode 是我本地protoc需要升级么? @qloog
from eagle.
升级下eagle: eagle upgrade
, 里面会升级生成 gin.pb.go
代码的命令。 @SonderEASE
from eagle.
eagle upgrade
牛逼! 我再请教一个问题,我现在要适配旧的接口,旧的接口返回的数据是这个格式的:
{ "code": 0, "data": [], "msg": "成功" }
这个data是个数组,我能让根据protoc生成的 http响应body中的data也是数组么? 或者有啥选项能把自带的这三个字段去掉吗?
@qloog
from eagle.
目前还不支持自定义整体的返回格式,比如
{
"code":0,
"data":[],
"msg":"成功"
}
改为
{
"errcode":0,
"data":[],
"message":"成功"
}
不过从扩展性上考虑的话,data使用map({}
)可能会更好一些。
from eagle.
目前还不支持自定义整体的返回格式,比如
{ "code":0, "data":[], "msg":"成功" }
改为
{ "errcode":0, "data":[], "message":"成功" }
不过从扩展性上考虑的话,data使用map(
{}
)可能会更好一些。
感谢!
from eagle.
Related Issues (20)
- docker-compose up -d 报错 HOT 1
- 数据库 是否 支持 postgresql ? HOT 8
- 能否提供一个只有http server 没有grpc的latout 模板 HOT 3
- wire生成wire_gen.go文件报错 HOT 5
- 密码加解密不对 HOT 2
- 项目的用户密码加密功能被取消了吗 HOT 2
- 脚手架的日志怎么都在根目录啊 HOT 2
- 为什么cron作为main包加载, 而不是作为init启动时直接加载呢? 这么设计有什么目的吗? HOT 1
- 微信交流群二维码已过期 HOT 1
- 请问 log 不支持 Debug 级别是出于什么考虑呢? HOT 5
- 这不是完全模仿kratos 得嘛,有啥优势 HOT 1
- make build 时候出现错误 HOT 8
- jwt token 验证 err: input does not match formatfmt.Sscanf HOT 1
- internal/routers/router.go line 70: apiV1.Use(middleware.Auth())报错 HOT 2
- 列消息队列支持-RabbitMQ或Kafak HOT 4
- Should Depend On sqlite3 v1.14.15 Instead of v2.01 HOT 1
- invalid argument "eagle:github.com/go-eagle/eagle/pkg/version" for "-t, --tag" flag: invalid reference format HOT 1
- page_value 跟 last_id 是啥关系 HOT 5
- 我该如何给基于grpc的http请求返回设置headers? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eagle.