Go Cookbook

collection of articles about programming in Go
By Krzysztof Kowalczyk

Table of Contents

3 ways to iterate
3 different way to implement an iterator in Go: callbacks, channels, struct with Next() function.

Advanced command execution with os/exec
Standard library os/exec is used for executing external programs. This article describes slightly more advanced use cases.

HTTPS for free using Let's Encrypt
In the past supporting HTTPS required paying for SSL certificate. Thanks to Let's Encrypt we get free SSL certificates and autocert library does all the hard work of provisioning them. Learn how to easily add HTTPS support and redirect HTTP traffic to HTTPS.

Using MySQL in Docker for local testing
How and why to run MySQL in Docker when developing Go web apps locally.

Simple serialization format for logging and analytics
How to use it, how it was designed and implemented.

How to rotate log files daily
How to rotate a log file once per day.

Porting Yoga from C to Go
Porting 4.5k loc of Yoga (Facebook's CSS flexbox implementation) from C to Go.

Embedding build number in Go executable
How to embed build number in Go executable.

Generating good unique ids
Generating unique ids comes up often in web services and distributed systems. This article describes what a good, unique id is and compares 7 libraries for generating ids.

Accessing GitHub API
GitHub offers a rich API for accessing information related to their service. This article will get you started writing programs that access the API.

Speeding up code with custom allocators
Allocations are often a silent performance killer. This article takes a well-known benchmark (construction of binary trees) and speeds it up ~4x by optimizing memory allocations.

Fuzzing markdown parser with go-fuzz
Fuzzing programs in Go is almost trivial thanks to go-fuzz. This article describes how I fuzzed my markdown parsing library.

Extracting files from .7z archives
Go doesn't have a native library for reading 7-Zip. This article describes extracting files from .7z archives using cmd-line 7z program.

Improving speed of SMAZ compressor by 2.6x/1.5x
A case study of improving performance with 3 micro-optimizations and demonstration of Go benchmarking tools.


If you like "Go Cookbook", share it on Twitter. To be notified about new chapters, follow @kjk.

Written by Krzysztof Kowalczyk