Go (Golang) Protocol Buffers Tutorial



Go (Golang) Protocol Buffers Tutorial

Go (Golang) Protocol Buffers Tutorial

Go (Golang) Protocol Buffers Tutorial

In this episode we are going to look at one of the most sought-after protocols when working with microservices and distributed systems: the protocol buffer encoding format. Protocol buffers is going to be useful when exploring gRPC in Go and in general in any programming language. Protocol buffers is a protocol designed by Google with the aim to be efficient, cross-platform, cross-language compatible, strongly typed and space efficient. It is particularly space efficient especially when compared to JSON or XML encoding protocol, for example JSON-RPC vs gRPC which uses protocol buffers under the hood as encoding format. In this specific example we are going to see how to generate the protocol buffers configuration files and how to generate code using the protocol buffers compiler, also known as protoc. We are going to encode some data into a file in a binary fashion using the protocol buffers format, although this can be easily replicated by sending the data across the network instead of storing it into a file.

Protocol Buffers Docs – https://developers.google.com/protocol-buffers/docs/proto3

How to setup protocol buffers compiler (protoc)
$ export GO111MODULE=on
$ go get google.golang.org/protobuf/cmd/protoc-gen-go
$ export PATH=”$PATH:$(go env GOPATH)/bin”

Source Code – https://play.golang.org/p/M0KPZMA7jKH

💼 Golang Cafe – https://golang.cafe
📬 Golang Cafe Jobs Newsletter – https://golang.cafe/newsletter
🐦 Golang Cafe Twitter – https://twitter.com/golangcafe
📣 Telegram Channel – https://t.me/golangcafe

Comments are closed.