Go微服务框架go-kratos实战学习02:proto 代码生成和项目代码编写步骤

Reads: 2835 Edit

参考资料

Mac 安装 protoc 指定版本
https://www.jianshu.com/p/580fb02f3929
https://www.cnblogs.com/china-golang/p/16142396.html

安装protoc

运行如下命令

go install github.com/golang/protobuf/protoc-gen-go@latest

1,出现异常protoc-gen-go-grpc: program not found or is not executable,需要安装以下命令

go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

2,出现异常protoc-gen-validate: 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 --validate_out: protoc-gen-validate: Plugin failed with status code 1.,需要安装以下命令

//第一步
git clone https://github.com/envoyproxy/protoc-gen-validate
//第二步
cd 你拉取的protoc-gen-validate项目的文件路径
//第三步
go install . 

hello.proto

syntax = "proto3";
package hello;

// 定义 go语言的包存放地址
option go_package="hello/hello";

// 定义扩展名
service Hello {
    rpc Run(Requests) returns(Responses) {}
}

message Requests {
    string name = 1;
}

message Responses {
    string message = 2;
}

protoc --go_out=plugins=grpc:./ ./hello.proto


Comments

Make a comment

www.ultrapower.com ,王硕的博客,专注于研究互联网产品和技术,提供中文精品教程。 本网站与其它任何公司及/或商标无任何形式关联或合作。