grpc-gateway

command module
v0.0.0-...-65cb45b Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2021 License: MIT Imports: 16 Imported by: 0

README

grpc-gateway

All the example you need to get started with writing grpc-gateway powered REST services in Go.

Running

Running main.go starts a web server on https://0.0.0.0:11000/. You can configure the port used with the $PORT environment variable, and to serve on HTTP set $SERVE_HTTP=true.

$ go run main.go

An OpenAPI UI is served on https://0.0.0.0:11000/.

Running the standalone server

Not implemented.

Getting started

After cloning the repo, there are a couple of initial steps;

  1. Install the generate dependencies with make install. This will install buf, protoc-gen-go, protoc-gen-go-grpc, protoc-gen-grpc-gateway and protoc-gen-openapiv2 which are necessary for us to generate the Go and swagger files.
  2. If you forked this repo, or cloned it into a different directory from the github structure, you will need to correct the import paths. Here's a nice find one-liner for accomplishing this (replace yourscmprovider.com/youruser/yourrepo with your cloned repo path):
    $ find . -path ./vendor -prune -o -type f \( -name '*.go' -o -name '*.proto' \) -exec sed -i -e "s;github.com/Seaman-hub/grpc-gateway;yourscmprovider.com/youruser/yourrepo;g" {} +
    
  3. Finally, generate the files with make generate.

Now you can run the web server with go run main.go.

Making it your own

The next step is to define the interface you want to expose in proto/node.proto. See https://developers.google.com/protocol-buffers/ tutorials and guides on writing protofiles.

Once that is done, regenerate the files using make generate. This will mean you'll need to implement any functions in server/nodeserver.go, or else the build will fail since your struct won't be implementing the interface defined by the generated file in proto/node.pb.go.

This should hopefully be all you need to get started playing around with the gRPC-Gateway!

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd
internal
OpenAPI
simple tool to merge different swagger definition into a single file
simple tool to merge different swagger definition into a single file

Jump to

Keyboard shortcuts

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