dev-openapi / protoc-gen-go_api

根据proto文件生成go调用

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

protoc-gen-go_api

一款用protobuf文件生成go的http调用代码。

安装

go install github.com/dev-openapi/protoc-gen-go_api@latest

使用

依赖googleapis的http.proto和annotations.proto。并且需要放到google/api/目录下

如果google/api是在工程文件目录下,执行以下脚本

protoc --go_api_out=out={dir}:. *.proto

如果google/api在其他文件目录下,执行以下脚本

protoc --proto_path={yourpath}:. --go_api_out=:. *.proto

注意

最新版本的protoc-gen-go要求go_package必须含有/,且会生成到$GOPATH/src目录下,所以建议把工程文件放到$GOPATH/src/git域名/git_group/目录下。

https://github.com/dev-openapi/wx-miniprogram 则该工程文件为 $GOPATH/src/github.com/dev-openapi/wx-miniprogram

另外,也可以指定protoc-gen-go的生成目录和设置source_relative相关配置,也可以生成到指定目录

protoc --go_out=.. --go_opt=paths=source_relative --go_api_out=out=..:. *.proto

这样会生成到上一层目录

About

根据proto文件生成go调用

License:Apache License 2.0


Languages

Language:Go 99.5%Language:Makefile 0.5%