brew install automake
brew install libtool
brew install protobuf
#go mod模式下进行安装
go install google.golang.org/protobuf/cmd/protoc-gen-go
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
go install github.com/asim/go-micro/cmd/protoc-gen-micro/v3@latest
测试:
syntax = "proto3";
package user;
option go_package ="./userpb";
message UserReq {
int64 user_id = 1;
string user_name = 2;
string password = 3;
}
message UserResp{
string reply=1;
}
service Hello{
rpc GetUser(UserReq) returns (UserResp) {};
}
在user文件路径下生成pb文件:
protoc --micro_out=. user.proto --go_out=. user.proto --go-grpc_out=require_unimplemented_servers=false:. user.proto
服务端:
package main
import (
"context"
"fmt"
"github.com/asim/go-micro/plugins/registry/consul/v3"
"github.com/asim/go-micro/v3"
"github.com/asim/g