Getting started with Go

Matthew Boyd
2 min readDec 23, 2021

Here I’ll provide some useful tips and tricks for getting started with Go.

Environment:

I cannot stress this enough, make sure to setup your IDE properly. This will save you so much time and effort in the long run. For me, I personally use Visual Studio Code. I only recently transitioned from a Java job to Go, so use to use IntelliJ.

Within VSC, make sure to install the Go plugin

I like these three plugins, the autocomplete on Kite + Go seems to work really effectively. These packages will allow you to type and for any of the native imports, it will automatically add them without you explicitly having to type them at the top when you save your document. The only flip side of this would be that when you explicity type an import and you haven’t already used this, because this would cause a compile error in Go, it removes it automatically on save — just something to look out for.

Hello world:

package main import "fmt"func main(){
fmt.Println("Hello world")
}

This is a very simple hello world, we can name the file “helloworld.go” and we can run it through the terminal with go run helloworld.go.

It will simply print helloworld.go. We can also create an executable binary from our code, we can simply do go build helloworld.go. This will create a helloworld.sh or helloworld.exe (depending on your operating system).

The fmt module is Go’s formatted input/output module.

Variables:

There are a few ways to work with variables:

declaring a variable:

var counter int64

This will declare a variable counter of type int64 and by default it will have a value of 0.

declaring and initialising a variable:

counter := 1

this := sign allows us to declare and initialise a variable. In this case, counter is created and equals the value 1 . Go will implicity infer the type that the variable requires.

You can declare multiple variables on one line:

var counter, accumulator int64

this will declare both counter and accumulator .

Equally, you can declare and initialise multiple variables:

counter, accumulator := 1,2

--

--