使用Envoy代理验证器和gogo protobuf进行Go验证。

huangapple go评论80阅读模式
英文:

Go validation using envoy proxy validator and gogo protobuf

问题

我正在尝试编写一个插件来生成验证Go文件。该插件使用https://github.com/mwitkow/go-proto-validators和envoy代理验证器https://github.com/envoyproxy/protoc-gen-validate。以下是我的命令:

protoc
--proto_path=${GOPATH}/src
--proto_path=${GOPATH}/pkg/mod/github.com/gogo/protobuf@v1.3.2
--proto_path=${GOPATH}/pkg/mod/github.com/envoyproxy/protoc-gen-validate@v0.1.0
--proto_path=.
--gogo_out=.
—-validate_out=“lang=go:.\”
--govalidators_out=gogoimport=true:.
proto/*.proto

当我运行上述命令时,我遇到以下错误。有没有专家能提供解决方法?感谢您的帮助。

zsh: command not found: --proto_path=.
zsh: command not found: --govalidators_out=gogoimport=true:.

在添加缺少的“/”之后:

protoc
--proto_path=${GOPATH}/src
--proto_path=${GOPATH}/pkg/mod/github.com/gogo/protobuf@v1.3.2
--proto_path=${GOPATH}/pkg/mod/github.com/envoyproxy/protoc-gen-validate@v0.1.0
--proto_path=.
--gogo_out=.
-—go_out=":./generated"
—-validate_out="lang=go:./generated"
--govalidators_out=gogoimport=true:.
proto/test.proto

我得到了**未知标志:-?**的错误提示。

英文:

I am trying write plugin to generate validate go files. Which uses https://github.com/mwitkow/go-proto-validators and envoy proxy validator https://github.com/envoyproxy/protoc-gen-validate. Below is my command

protoc  \
--proto_path=${GOPATH}/src \
--proto_path=${GOPATH}/pkg/mod/github.com/gogo/protobuf@v1.3.2 \
--proto_path=${GOPATH}/pkg/mod/github.com/envoyproxy/protoc-gen-validate@v0.1.0
--proto_path=. \
--gogo_out=. \
—-validate_out=“lang=go:.\”
--govalidators_out=gogoimport=true:. \
proto/*.proto

when I run above command I am getting below error? any suggestion expert on how to resolve this. Appreciate your help.

zsh: command not found: --proto_path=.
zsh: command not found: --govalidators_out=gogoimport=true:. 

After adding the missing "/"

protoc  \
--proto_path=${GOPATH}/src \
--proto_path=${GOPATH}/pkg/mod/github.com/gogo/protobuf@v1.3.2 \
--proto_path=${GOPATH}/pkg/mod/github.com/envoyproxy/protoc-gen-validate@v0.1.0 \
--proto_path=. \
--gogo_out=. \
-—go_out=":./generated" \
—-validate_out="lang=go:./generated" \
--govalidators_out=gogoimport=true:. \
proto/test.proto

I am getting Unknown flag: -?

答案1

得分: 2

你在get-validate后面漏掉了\...

protoc  \
--proto_path=${GOPATH}/src \
--proto_path=${GOPATH}/pkg/mod/github.com/gogo/protobuf@v1.3.2 \
--proto_path=${GOPATH}/pkg/mod/github.com/envoyproxy/protoc-gen-validate@v0.1.0 \
--proto_path=. \
--gogo_out=. \
—-validate_out="lang=go:." \
--govalidators_out=gogoimport=true:. \
proto/*.proto
英文:

you missed \ after get-validate and later...

protoc  \
--proto_path=${GOPATH}/src \
--proto_path=${GOPATH}/pkg/mod/github.com/gogo/protobuf@v1.3.2 \
--proto_path=${GOPATH}/pkg/mod/github.com/envoyproxy/protoc-gen-validate@v0.1.0 \
--proto_path=. \
--gogo_out=. \
—-validate_out="lang=go:." \
--govalidators_out=gogoimport=true:. \
proto/*.proto

huangapple
  • 本文由 发表于 2021年8月18日 20:52:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/68832770.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定