A minimal repo containing all the boilerplate for getting started with GopherJS using gRPC-Web
MIT License
A minimal repo containing all the boilerplate for getting started with GopherJS using gRPC-Web. Clone and use as a base for your own experimentation with GopherJS and gRPC-Web!
It comes complete with a Go generate template for statically serving your generated JS code from the backend server.
A recording of my presentation at the Go Devroom at FOSDEM 2018, in which I clone this repo I perform a small demo of its use.
Generating the files requires the protoc
protobuf compiler.
Please install it according to the
installation instructions
for your specific platform.
After cloning the repo, there are a couple of initial steps;
make install
.protoc-gen-go
and protoc-gen-gopherjs
, whichmake generate_cert
.find
one-liner for accomplishing thisyourscmprovider.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/johanbrandhorst/grpcweb-boilerplate;yourscmprovider.com/youruser/yourrepo;g" {} +
make generate
.protoc
and it is accessible in your $PATH
, and make sureNow you can run the web server with make serve
.
The next step is to define the interface you want to expose in
proto/web.proto
. See https://developers.google.com/protocol-buffers/
tutorials and guides on writing protofiles.
Once that is done, regenerate the backend and frontend files using
make generate
. This will mean you'll need to implement any functions in
backend/backend.go
, or else the build will fail since your struct won't
be implementing the interface defined by the generated file in proto/server/
.
It also means you can start using the functions exposed by the server
in your frontend client in frontend/frontend.go
.
Every time you make changes to any files under frontend/
you'll
need to regenerate the JS files using make generate
.
This should hopefully be all you need to get started playing around with the GopherJS gRPC-Web bindings!
This repo is not a general example of how to use the GopherJS gRPC-Web bindings. For such an example, please see https://github.com/johanbrandhorst/grpcweb-example and https://grpcweb.jbrandhorst.com.
This repo is also not a particularly good example of how to write an app with GopherJS. Please explore the tutorials and wiki pages on https://github.com/gopherjs/gopherjs and check out frameworks such as https://myitcv.io/react and https://github.com/gopherjs/vecty for a better way to write GopherJS apps.