GRPC安装使用教程

1、下载 protocolbuffers

Release Protocol Buffers v26.1 · protocolbuffers/protobuf · GitHub

2、加入环境变量

需要将下载后的bin目录,加入环境变量

输入protoc表示加入成功

 3、下载grpc依赖

go get google.golang.org/grpc

4、安装protoc-gen-go 

grpc可能存在调用其他语言,所以需要protocol,除了这个编译器还需要各个语言的代码生成工具城为protoc-gen-go,同样需要加入环境变量

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

4、生成proto文件

syntax = "proto3";
//当前目录生成
option go_package = ".;service";

package helloworld;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply);
}

// The request message containing the user's name.
// 1为消息号
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}

5、生产go代码

编写好文件后生成go代码,远程调用一般使用grpc中代码

protoc --go_out=. hello.proto
protoc --go-grpc_out=. hello.proto

6、具体使用操作

https://github.com/lemonth12/grpc

7、安全grpc

ssl/tls认证

Win32/Win64 OpenSSL Installer for Windows - Shining Light Productions  ,下载后需要配置环境变量

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值