A 16-post collection

Persisting Application Configuration In Golang

I often observe that configuration is overlooked in books and posts devoted to application development. Authors only slightly touch it at best. I believe it's quite an important topic on its own and deserves a dedicated post. So in this post you will find explained examples of how to make persistent configurations in Go applications.

I will demonstrate how to work with configuration for two most popular formats: json and yaml. In examples we will store and load config of hypothetical cluster manager captured with the following structs:

type Cluster struct {  
    Name       string
    DataCentre string
    Nodes      []string

type Configuration struct
Read more »

Working with InfluxDB in Go

InfluxDB is one of the most popular time series databases on the market. In this post you will learn its key concepts, as well as, how to interact with InfluxDB in Go on example.


InfluxDB design conceptually reminds relational database. Don't get me wrong, it is not a relational database in any sense. It doesn't impose schema on your data and doesn't implement SQL. But... it has equivalent concepts and is operated via DSL looking quite similar to SQL.

Key concepts

If you are new to InfluxDB, have a look at key concepts with examples here. If you need

Read more »

How To Build Microservice With MongoDB In Golang

These days Golang grows in popularity for writing RESTful microservices. Quite often these services utilize MongoDB as persistence storage. In this post we will build a simple book store microservice using both Go and MongoDB. We will connect to MongoDB with mgo driver and use curl to test the microservice.


MongoDB took market with storm by its simplicity, high availability and document orientation. The advantages of using documents over relational tables are:

  • Documents correspond to native data types in many programming languages.
  • Embedded documents and arrays reduce need for expensive joins.
  • Dynamic schema supports fluent polymorphism.
What is a
Read more »

goimports vs gofmt

It is hard to find a Go developer who have never heard of gofmt. From the moment we start learning the language, Go documentation including Effective Go preaches us that code MUST be formatted with standard gofmt tool. While gofmt attracks much attention, goimport is overlooked despite often being more useful. In this post we will learn how they differ on example.


To save some space, I would provide only a snippet from a file, but feel free to get the whole one from GitHub and experiment with it.

Snippet of our unformatted example:

package main

import (  
Read more »

RESTful web service in Go using Goji

Although net/http provides all necessary abstractions to create web services out of the box, there are alternative packages providing additional features and allowing to minimize boilerplate code. Today we will have a look at how to implement a web service with Goji.

Example of Goji web service

Let's start with a working example. You can get if from GitHub.

package main

import (  


type book struct {  
    ISBN    string "json:isbn"
    Title   string "json:name"
    Authors string "json:author"
    Price   string "json:price"

var bookStore = []book{  
        ISBN:    "0321774639",
        Title:   "Programming
Read more »