GopherJS Client and gRPC Server - Introduction

I’ve been using gRPC and Go a lot in the last year. At Cognitive Logic every one of our backend services is implemented with Go and gRPC, and it enables us to abstract away most of the complexities of networked micro services and keep interfaces typed and well defined using Google protobuffers.

I really enjoy using both, but sometimes I need to write a frontend to a web server and I despise writing Javascript. So what do? Use Go of course!

With GopherJS it’s possible to write safe statically typed code that transpiles to Javascript. It comes with a couple of quirks but as long as I don’t have to use Javascript I’m happy.

Naturally, I want to be able to use Go and gRPC in the backend as well if I can, and with the use of the gRPC HTTP Gateway it becomes as simple as writing a normal gRPC service.

So what are the steps required to get a GopherJS frontend client talking to a gRPC backend seamlessly? In short:

If you want to skip ahead, the finished example can be found on my github.

Preparation

Some structure will help organization. Let’s create a client, server, and protos folder:

$ tree -L 1 -d
.
|-- client
|-- protos
`-- server

Next up we’ll create the proto interface.