[golang]-go-micro

一、安装

1.1.配置环境

go get github.com/micro/micro
go get github.com/golang/protobuf

1.2.代码生成配置

1.安装protoc

访问

https://github.com/protocolbuffers/protobuf/releases

下载protoc-3.13.0-win64.zip放到path环境

2.安装protoc-gen-micro,

go get github.com/micro/micro/v3/cmd/protoc-gen-micro@master

生成exe放到path环境

3.安装 protoc-gen-go

https://github.com/golang/protobuf/tree/master/protoc-gen-go

生成exe放到path环境

4.生成文件

到项目目录,例如执行下面代码 后面helloworld.proto为文件名

helloworld.proto文件

syntax="proto3";

service HelloWorld{
    rpc Hello(HelloRequest) returns(HelloResponse){}
}
message HelloRequest{
    string name=1;
}
message HelloResponse{
    string greeting=2;
}

到helloworld.proto所在目录,cmd命令行

D:\goResources\src\gocode\basic-code\go-high\微服务\go-micro\go-Micro-helloworld\proto>protoc-gen-go --micro_out=. --go_out=. helloworld.proto

自动生成代码

posted on 2023-03-08 00:03  共感的艺术  阅读(76)  评论(0)    收藏  举报