• Stars
    star
    455
  • Rank 93,161 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 5 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

grpc-gateway-boilerplate

Run on Google Cloud

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

Requirements

Go 1.17+

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

If you want to use a separate gRPC server, for example one written in Java or C++, you can run the standalone web server instead:

$ go run ./cmd/standalone/ --server-address dns:///0.0.0.0:10000

Getting started

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

  1. 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' -o -name '*.yaml' \) -exec sed -i -e "s;github.com/johanbrandhorst/grpc-gateway-boilerplate;yourscmprovider.com/youruser/yourrepo;g" {} +
  2. 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/users/v1/user.proto. See https://developers.google.com/protocol-buffers/ tutorials and guides on writing Protobuf files. See the Buf style guide for tips on how to structure your packages.

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

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

More Repositories

1

certify

Automatic client and server certificate distribution and maintenance
Go
458
star
2

grpc-postgres

An example repo of how I like to use postgres with gRPC
Go
284
star
3

grpc-auth-example

Examples of client authentication with gRPC
Go
95
star
4

grpcweb-example

An example implementation of a GopherJS client and a Go server using the Improbable gRPC-Web implementation
Go
94
star
5

protobuf

GopherJS Bindings for ProtobufJS and gRPC-Web
Go
82
star
6

grpc-web-compatibility-test

Test various implementations of gRPC-Web Clients with various implementations of gRPC-Web proxies
JavaScript
62
star
7

wasm-experiments

Go
62
star
8

grpc-wasm

gRPC-Web implementation in Go, built using the WASM architecture target
Go
50
star
9

grpc-json-example

Example of using gRPC-Go with JSON as the transport encoding
Go
47
star
10

grpcweb-boilerplate

A minimal repo containing all the boilerplate for getting started with GopherJS using gRPC-Web
Go
44
star
11

grpcweb-wasm-example

Small example server using gRPC-Web via the gRPC-Go WASM fork
JavaScript
43
star
12

chunker

Small demo of a server splitting binary blobs into streamed chunks
Go
39
star
13

connect-gateway-example

Example of using the gRPC-Gateway with Connect
Go
27
star
14

gopherjs-grpc-websocket

An example implementation of bridging gRPC with a GopherJS frontend over Websockets
Go
25
star
15

grpc-web-go-react-example

Example of using Go and React/TypeScript with gRPC-Web
TypeScript
23
star
16

rust-grpc-web-wasm-test

Go
15
star
17

sortslice

Warn if user provides a non-slice to sort.Slice
Go
12
star
18

bazel-mono

Playing around with using Bazel for CI
Starlark
11
star
19

gogoproto-experiments

Testing various Go protobuf and gRPC packages with GoGoProtobuf
Go
9
star
20

redeploy

Simple application for redeploying containers when Docker hub webhooks are sent
Go
8
star
21

protoc-gen-gopherjs

This repo has moved
8
star
22

presentations

My presentations
Go
7
star
23

go-protobuf-plugin-versioning-example

An example of easy consistent versioning of Go based Protobuf plugins
Go
6
star
24

simple-grpc

Minimal gRPC example
Go
6
star
25

collapse-gitlab-files

A small userscript for collapsing all files on a GitLab merge request diffs page
JavaScript
5
star
26

concurrency

Concurrency example
Go
5
star
27

grpc-web-generators

Dockerfile for generating grpc-web protofiles.
Dockerfile
5
star
28

fetch

The Go http.Transport interface implemented over the WHATWG Fetch API
Go
5
star
29

gopherjs-grpc-web-example

Example implementation of a GopherJS gRPC-web client talking to a Go gRPC server
Go
4
star
30

blog

My blog
HTML
4
star
31

gopherjs-json

Convenience functions for interacting with JSON in GopherJS
Go
3
star
32

papers

Collection of talk proposals
3
star
33

cat-collection

JavaScript
3
star
34

hashipet

HashiPet API
Go
3
star
35

bomberman

A bomberman clone me and some friends from uni made as part of a C++ project
C++
2
star
36

chronic-pain-tracker

Tracks pain through the day
Go
2
star
37

rust-experiments

2
star
38

delete-gitlab-registry-tags

Simple userscript that adds a button to the GitLab registry page for mass tag deletion
JavaScript
2
star
39

aoc2019

Advent of Code 2019
Rust
2
star
40

grpcweb-presentation

Files for my presentation about my gRPC-Web bindings
Protocol Buffer
2
star
41

gopherjs-grpc-web

A GopherJS binding and generator for gRPC-web
JavaScript
2
star
42

templ-exp

1
star
43

websocket

Implementing Go interfaces in WASM using the Websockets API
1
star
44

buf-example

Using buf to develop APIs with protocol buffers
1
star
45

docker-go-protobuf

For building a simple Docker container with Go and Protobuf installed
1
star
46

moq-vendor-bug

Go
1
star
47

go-wazero-experimenting

Go
1
star
48

rag-experiment

Go
1
star
49

grpc-web

gRPC-Web implementation in Rust, targeting WebAssembly
1
star