Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

49. protobuf 定义里面加校验器 #49

Open
guonaihong opened this issue Mar 20, 2024 · 0 comments
Open

49. protobuf 定义里面加校验器 #49

guonaihong opened this issue Mar 20, 2024 · 0 comments

Comments

@guonaihong
Copy link
Owner

guonaihong commented Mar 20, 2024

需求

在grpc或者protobuf里面如何使用数据校验功能。

技术问题

  1. 由于protobuf是直接生成struct。现在go流行的校验器是直接书tag。在两种解决方法 1.protobuf写规则 生成到struct tag 2. protbuf写规则,通过扫描ast重写tag
  2. 书写胶水层代码

解决过程

  1. 找到 go install github.com/favadi/protoc-go-inject-tag@latest 工具提取protobuf注释里面的数据,重写tag
  2. 集成到ci/cd里面的语法
go install github.com/favadi/protoc-go-inject-tag@latest      
find .  -name '*.go' -exec protoc-go-inject-tag -input={} \;

中间件代码

TODO 有时间写完笔记。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant