I have started working on building webservices in go. This has been a great learning experience and will be sharing my learnings in this series which I am calling Webservices with Go. This will mostly be a 4 post series with 2 posts covering setting up webservice in Go and creating ReST APIs with JSON-over-HTTP. The latter 2 posts covering RPC based server using protobuf and grpc and how to support both RPC and ReST using a gateway.

Why webservice? Because APIs are one of the best method to access resources of a system. …

This post is not about details of cassandra database. Instead it is dedicated to how one can bring up a multinode setup of cassandra on a single host machine using docker. For personal projects, its really not a feasible or affordable mean for everyone to have multiple host system for understanding a NoSQL multi-DC scenario.


I am assuming that you have docker already installed in your system.

Assuming a fresh start

Check for docker instances

Just like any language which provides constructs to build concurrent running tasks like - threads in java, Go also provides constructs called Goroutines and channels. This article will be discussing about these constructs and discuss some sample code.


Goroutines are functions which executes concurrently along with the main program flow. Simply put the main program is the main goroutine and any other goroutine spawned will run under the umbrella of the main goroutine until the lifecycle of the main goroutine. Its comparable to a lightweight thread in java. …


A function is a block of code that takes some input(s), does some processing on the input(s) and produces some output(s). Function in Go are first class citizens similar to javascript.


A function in Go is declared using func keyword. A function has a name, a list of comma-separated input parameters along with their types, the result type(s), and a body.

func <name>(arg <type>) <return type> {
return <val>


func firstFn(arg1 int, arg2 int) int {
val := arg1 + arg2
fmt.Println("I am a method and my value is : ", val)
return val

Calling a function

Calling a…


A pointer is a variable that stores the memory address referenced by another variable. Pointers have the power to mutate data they are pointing to.

If you are from C/C++ background, then you would have certainly worked with pointers(*). Pointers are one of the most complex and most powerful paradigms in a programming language.

Initialize a pointer

arrA := [...] int{1, 3, 5}
var b *int = &arrA[0]

Observe the & (address of) operator. We have discussed this in one of our previous posts when we discussed about arrays and slice.

Modifying the pointer referenced value

arrA := [...] int{1, 3, 5}
var b *int = &arrA[0]
fmt.Println("value : "…

This post is dedicated to yet another datatypes in Go — maps and structs. Lets start!


Map is a datastructure which stores <key, value> pair. The key of a map can be a value type datatypes only i.e. you can make int, string, array as key. You cannot make reference type like a slice as a map key. Maps can be initialised as

Method 1
variable := map[<key type>]<value type> {comma separated key,value}
emptyMap := map[string]int{}
ORarrMap := map[[3]string]int{}OR
statePop := map[string]int {
"UP": 235,
"Maharashtra": 200,
"Delhi": 150,
"MP": 175,
"Rajasthan": 165,
"Karnataka": 150,
fmt.Printf("statewise population map : %v", statePop)…

In this post, I will be discussing about the datatypes — arrays and slices.


Arrays is a collection of data stored in contiguous memory locations. Arrays in Go can be initialized as

Method 1
<variable> := [size of array] <type> {valueset}
This will initialize an array of size as specified in - <size of array>
grades := [3] int{97, 98, 99}
Method 2
<variable> := [...] <type> {valueset}
This will initialize an array with size as in the number of elements in the valueset.
grades := [...] int{97,98, 99, 100}
size - 4
Method 3
var <variable> [size of array] <type>

Prateek Gupta

Senior Software Developer from India. Fancy learning and building stuff. Making a habit to share knowledge via blogs

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store