Skip to content

grpc代理简单示例,http协议转grpc协议,简单易懂,200行代码。

License

Notifications You must be signed in to change notification settings

changsongl/grpc-gateway-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grpc-gateway-example

grpc代理简单示例,http协议转grpc协议。

client ---http1.1---> proxy ---grpc---> grpc-server

alt text

Protobuf

syntax = "proto3";

option go_package = "/helloworld";

package helloworld;

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

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

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

Run

# 运行proxy和grpc服务
go run .
# 请求proxy
curl -X POST -H "Content-Type:application/json" -H "Package:/helloworld" \
-H "Service:Greeter" -H "Method:SayHello" \
http://127.0.0.1:8080/ -d '{"name": "Jason"}' 

# proxy返回了grpc response
{"message":"Hello, Jason!"}%   

About

grpc代理简单示例,http协议转grpc协议,简单易懂,200行代码。

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages