Protocol Buffers in go

If you want to get started quickly with Google Protocol Buffers in the Go Programming Language lets follow the guide from

https://developers.google.com/protocol-buffers/docs/gotutorial

First we download from GitHub protocolbuf project:

git clone https://github.com/protocolbuffers/protobuf.git

Then we setup our Go project.

mkdir -p ~/protobuf/src/github.com/protocolbuffers/protobuf/examples/

From git repo, locate examples folder

cd ~/GIT/protobuf/examples

Then copy the source code to our Go project:

cp Makefile ~/protobuf/src/github.com/protocolbuffers/protobuf/examples
cp *go ~/protobuf/src/github.com/protocolbuffers/protobuf/examples
cp *proto ~/protobuf/src/github.com/protocolbuffers/protobuf/examples

Setup the GOHOME variable

export GOPATH=~/protobuf

Then we install protobuf protoc compiler: Download protoc from following location then unzip in your preferred folder

https://github.com/protocolbuffers/protobuf/releases

For instance I unzip into my protoc folder:

Unzipping protoc compiler

Update your path to locate protoc

export PATH=~/protoc/bin:$PATH

Then we install go plugin

go get -u github.com/golang/protobuf/protoc-gen-go

Update your path to locate protoc-gen-go. (Installed in previous step by go get)

export PATH=~/protobuf/bin:$PATH

This is the go project setup, now lets build the tutorial.

Go to examples folder

cd ~/protobuf/src/github.com/protocolbuffers/protobuf/examples
make clean
make go
Building Go Tutorial

Running the sample

Adding records
Listing records

Leave a Reply

Your email address will not be published. Required fields are marked *