grpc-sandbox

module
v0.0.0-...-88920c5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2022 License: MIT

README

gRPC-JSON Transcoder

Go Report Card Protobuf, gRPC, Envoy example using buf.build tool.

If you have Go, make and buf.build tool installed, you should be able to just execute.

 make

I recommend completing Tour of Buf to understand the functionality of both the CLI and the BSR.

Envoy

Envoy is a very flexible proxy. It's implements gRPC-JSON transcoding as a filter. In order to to start transcoding you need to:

  • Generate the proto descriptor of gRPC service
    make image-gen 
    
  • Run Envoy using Docker
    make docker-run 
    
  • Build a gRPC-service:
    make run 
    

By default, when transcoding occurs, gRPC-JSON encodes the message output of a gRPC service method into JSON and sets the HTTP response Content-Type header to application/json.

You can verify that gRPC-JSON transcoding works fine by sending the following request:

curl -X 'GET' \
  'http://localhost:8080/v1/example/ping' \
  -H 'accept: application/json'

gRPCurl

You can use gRPCurl to interact with gRPC server without using an Envoy proxy.

Example of gRPCurl usage:

grpcurl \
  -plaintext \
  localhost:9092 
  describe                     

grpcurl \
  -plaintext \
  -d '{}' \
  localhost:9092 \ 
  example.v1.Example.Ping

Tests

You can use make command to run unit-tests without running the app or building envoy container:

make go-test 

Directories

Path Synopsis
example
grpc/gen/proto/example/v1
Package grpc is a reverse proxy.
Package grpc is a reverse proxy.
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL