gopherjs-grpc-websocket icon indicating copy to clipboard operation
gopherjs-grpc-websocket copied to clipboard

An example implementation of bridging gRPC with a GopherJS frontend over Websockets

gopherjs-grpc-websocket

An example implementation of bridging a gRPC backend with a GopherJS frontend over Websockets, XHR requests and the grpc-gateway.

A large focus of this project is to show that you can implement both simple HTTP requests and complex bi-directional websocket streaming without compromising generated file size. The generated js for this example weighs in at 942KB.

This takes inspiration from projects like https://github.com/philips/grpc-gateway-example.

Generate the proto files

This requires installing the go programs from the vendor folder and protoc. It also assumes you have python3 in your $PATH.

Download the latest protoc from github.com

Install go dependencies:

$ go install ./vendor/...

Generate!

$ ./generate.py

Generate the client

Install gopherjs (note that gopherjs cannot be vendored, see https://github.com/gopherjs/gopherjs/issues/415):

$ go get -u github.com/gopherjs/gopherjs/js

Generate!

$ go generate ./client/

This creates a go-bindata-compiled file which can easily be served from the server.

Running the server

$ go run main.go

Navigate to localhost and check it out!