Creating a microservice
for the 1st time with go
Go is an open source programming language that makes it
easy to build simple, reliable, and efﬁcient software.
Robert Griesemer, Rob Pike and
Ken Thompson started sketching
the goals for a new language on
the white board on September 21,
Go is a programming language
designed by Google to help solve
Google's problems, and Google
has big problems.
An attempt to combine the
ease of programming of an
typed language with the
efﬁciency and safety of a
statically typed, compiled
• C family (basic syntax)
• Pascal / Modula / Oberon family (declarations,
• Newsqueak, Limbo (concurrency)
• Multi-value returns
• No exception handling. Pleasant error handling.
• Gourotines instead of threads
• Object-oriented? Yes and no.
No type hierarchy. Interfaces.
• No pointer arithmetic for safety:
no memory illegal address risk
• Garbage collected
• go fmt
• go lint
• go vet
• go test
• go tool cover
go get github.com/henvic/picel
• Programming time?
• Package main: executable program
• Others: shared libraries
- don’t use relative internally
- use the path to where the repo is published
• Subpackages = subdirectories
No ofﬁcial package
• The designers of the language decided not to
do it for a reason.
• But what if you want to guarantee a speciﬁc
• gpm: https://github.com/pote/gpm
• go build
• You get a single binary by default.
• gox tool to build to multiple platforms easily
or just use https://gobuilder.me/
The go way
• Unused variable?
• Unused import?
= No compiling :( … :)
• Just discovered: ﬁx it automagically :)
Productivity += 1000
• godoc -http=:6000 to see the docs on your computer or use
• Go likes to have all your src, pkg, bin inside a
• But don’t worry. This doesn’t matter for end users
of your application, given you’re release
Useful packages, methods
• fmt.Println(“like console.log”)
• fmt.Sprintf(“%+v is %v old”, person,
• ﬂag: ./cmd -backend “https://google.com/”
Flag: backend, value: https://google.com/
• number, err := strcov.Atoi(“2442”)
number is 2442 (int), err is nil
with multiple return params
• Docker is built in go
• We’ve a microservice that is designed to work
with default options
• Why not build a docker container for it?
MAINTAINER Henrique Vicente
RUN apt-get update
RUN apt-get install -y \
Docker Hub Registry
• Add repo for automatic building on Docker Hub
Registry to have your package certiﬁed
• You can install with
docker pull henvic/picel
• See also Dockerﬁle.dev
Some nice go projects