Part 1: Introduction and Installation

This is the first tutorial in our Golang tutorial series. This tutorial provides an introduction to Go and also discusses the advantages of choosing Go over other programming languages. We will also learn how to install Go in Mac OS, Windows and Linux.

Introduction

Go also known as Golang is an open source, compiled and statically typed programming language developed by Google. The key people behind the creation of Go are Rob Pike, Ken Thompson and Robert Griesemer. Go was made publicly available in November 2009.

Go is a general-purpose programming language with a simple syntax and is backed by a robust standard library. One of the key areas where Go shines is the creation of highly available and scalable web apps. Go can also be used to create command-line applications, desktop apps and even mobile applications.

Advantages of Go

Why would you choose Go as your server side programming language when there are tonnes of other languages such as python, ruby, nodejs... that do the same job.

Here are some of the pros which I found when choosing Go.

Simple syntax

The syntax is simple and concise and the language is not bloated with unnecessary features. This makes it easy to write code that is readable and maintainable.

Easy to write concurrent programs

Concurrency is an inherent part of the language. As a result, writing multithreaded programs is a piece of cake. This is achieved by Goroutines and channels which we will discuss in the upcoming tutorials.

Compiled language

Go is a compiled language. The source code is compiled to a native binary. This is missing in interpreted languages such as JavaScript used in nodejs.

Fast compilation

The Go compiler is pretty amazing and it has been designed to be fast right from the beginning.

Static linking

The Go compiler supports static linking. All the Go code can be statically linked into one big fat binary and it can be deployed in cloud servers easily without worrying about dependencies.

Go Tooling

Tooling deserves a special mention in Go. Go comes bundled with powerful tools that help developers write better code. Few of the commonly used tools are,

  • gofmt - gofmt is used to automatically format go source code. It uses tabs for indentation and blanks for alignment.
  • vet - vet analyses the go source code and reports possible suspicious code. Everything reported by vet is not a genuine problem but it has the capability to catch errors that are not reported by the compiler such as incorrect format specifiers when using Printf.
  • golint - golint is used to identify styling issues in the code.
Garbage collection

Go uses garbage collection and hence memory management is pretty much taken care automatically and the developer doesn't need to worry about managing memory. This also helps to write concurrent programs easily.

Simple language specification

The language spec is pretty simple. The entire spec fits in a page and you can even use it to write your own compiler :)

Opensource

Last but not least, Go is an open source project. You can participate and contribute to the Go project.

Popular products built using Go

The following are some of the popular products built using Go.

  • Google developed Kubernetes using Go.
  • Docker, the world famous containerization platform is developed using Go.
  • Dropbox has migrated it's perfomance critical components from Python to Go.

Installation

Go is supported on all the three platforms Mac, Windows, and Linux. You can download the binary for the corresponding platform from https://golang.org/dl/

Mac OS

Download the Mac OS installer from https://golang.org/dl/. Double tap to start the installation. Follow the prompts and this should have Golang installed in /usr/local/go and would have also added the folder /usr/local/go/bin to your PATH environment variable.

Windows

Download the MSI installer from https://golang.org/dl/. Double tap to start the installation and follow the prompts. This will install Go in location c:\Go and will also add the directory c:\Go\bin to your path environment variable.

Linux

Download the tar file from https://golang.org/dl/ and unzip it to /usr/local.

Add /usr/local/go/bin to the PATH environment variable. This should install Go in Linux.

In the next part Golang tutorial part 2: Hello World of this series, we will set up the Go workspace and write our first Go program :)

Please provide your valuable feedback and comments. Thanks for reading.

Next tutorial - Hello World

Naveen Ramanathan

Naveen Ramanathan has more than 11 years of programming experience in backend and mobile app development. If you would like to hire him, please mail to naveen[at]golangbot[dot]com