1.下载protoc-gen-go文件
go install github.com/golang/protobuf/protoc-gen-go@latest
2.生成一下相关文件报错了
adong@adong Test % protoc --go_out=. api.proto
protoc-gen-go: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable
--go_out: protoc-gen-go: Plugin failed with status code 1.
网上修改各种环境变量都不行,最后找到一种有效方法:
找到protoc-gen-go文件目录/Users/adong/go/bin,使用下面命令拷贝一下
cp protoc-gen-go /usr/local/bin/
3.再次使用第2步命令又报错如下:
protoc-gen-go: invalid Go import path;The import path must contain at least one forward slash (‘/‘)
解决办法是修改go_package的路径
在proto文件中
option go_package = "yourpackage";
需要加上“./”,变成
option go_package = "./yourpackage";
网友评论