<aside> ℹ️

Disclaimer: This doesn’t aim to be “the ultimate guide to Go”, but rather only include things I want to keep track of. I am an experienced programmer, so I’ll basically jot down Go-specific syntax and quirks, and whatever else I may want to revisit or keep in mind.

For a more complete experience see other sources like https://gobyexample.com/ https://go.dev/tour/ https://learnxinyminutes.com/docs/go/ https://quickref.me/go

If you have prior experience with JS/TS like me: https://github.com/miguelmota/golang-for-nodejs-developers https://www.pazams.com/Go-for-Javascript-Developers/

</aside>

Table of Contents

Basic types

bool

string

int  int8  int16  int32  int64
uint uint8 uint16 uint32 uint64 uintptr

byte // alias for uint8

rune // alias for int32
     // represents a Unicode code point

float32 float64

complex64 complex128

The int, uint, and uintptr types are usually 32 bits wide on 32-bit systems and 64 bits wide on 64-bit systems. When you need an integer value you should use int unless you have a specific reason to use a sized or unsigned integer type.

String interpolation

Doesn’t really exist. You can either use a + b or fmt.Sprintf(”%s%s”, a, b).

Multi-line strings

Strings with backticks/tildes (```) can be multi-line.

Packages

All Go programs are made up of packages. They must all have a main package.

By convention, the package name is the same as the last element of the import path. For instance, the "math/rand" package comprises files that begin with the statement package rand.

A name will be exported if it starts with a capital letter. This applies everywhere. Unexported names are (obviously) not available outside their respective scopes.

A package can be composed of multiple files. However, only 1 package may exist per folder.

Variables

var i, j int

var k, l string = "k", "l”

They can be defined at a package or block level. If the initialiser is provided, the type can be omitted.

The := operator

Only available inside functions, it is a shorthand for var: