Skip to content

Latest commit

Β 

History

17 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

gRPC on Go

This project is a small starting point for building a Go client and server that communicate with gRPC. The accompanying gRPC article series explains the contract, generated code, server, and client.

Install πŸ—

Install the Protocol Buffers compiler using the instructions for your platform. On macOS with Homebrew:

brew install protobuf

Install the Go plugins for the Protocol Buffers compiler. The official gRPC-Go quick start lists the same prerequisites.

make install

Generate the client and server bindings, then verify both modules:

make gen
make test

Run the server:

make server

In another terminal, run the client:

make client

The sample uses plaintext transport only for local development. Configure TLS and authentication before exposing a gRPC service outside your trusted development network.

Invoking RPCs πŸš€

# Note: since we are not using TLS all the calls are with -plaintext flag
grpcurl -plaintext localhost:8080 list
grpcurl -plaintext localhost:8080 Inventory.GetBookList

Useful commands πŸ“‘

Generate Go stubs

make gen

Clean stubs

make clean

Common issues and FAQ ❓

  1. VS Code complains about imports?

Known issue with the Proto3 VS Code plugin. Add the following to your settings.json file

"protoc": {
        "path": "/path/to/protoc",
        "compile_on_save": false,
        "options": [
            "--proto_path=protos/v3",
            "--proto_path=protos/v2",
            "--proto_path=${workspaceRoot}/proto",
            "--proto_path=${env.GOPATH}/src",
            "--java_out=gen/java"
        ]
    }

Run which protoc to find your proto compiler path.

  1. Auto formatter doesn't work?
brew install clang-format

Add the following to your settings.json

{
    // ...
    "editor.formatOnSave": true
    // ...
}

About

🎯 A simple gRPC web service written in Go

Topics

Resources

Stars

21 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages