Go - Get Started
How to get started with the Go programming language
There are many reasons somebody would want to learn the Go programming. It is a fast, compiled language with a friendly syntax that serves as the backbone of the modern day Cloud powered world.Hello World
One does not start playing piano by going straight to Beethoven, nor does one start painting by creating their own Starry Night. Therefore one does not start learning a programming language by writing their own operating system right away. Every programmer's journey starts with a simple Hello World program. The purpose of this "Hello World" program is to serves as a gentle introduction to a language's most basic syntax. The tradition of a "Hello World" program as one's first program started with Brian Kernighan in his book The C Programming language and has been part of the developer's journey ever since.Get Go(ing)
With the history lesson done it is time to get started writing some Go code! To get started one should download the Go programming language from the official website go.dev (or through their prefered package manager). This download will install the Go compiler and the required tooling. Once the download has finished it is time to boot up your prefered IDE and paste the below code in a file called main.go:
package main
import "fmt"
func main() {
fmt.Println("Hello world!")
}
Lets disect what is happening here.
- package main declares a special package called main which informs the Go compiler that this file contains the code for an executable
- import fmt imports the fmt package which contains functions to print the string "Hello World" to the screen
- func main declares the main function which is the entry point into our program, each program can have only 1 main function
- fmt.Println tells our program to call the function Println stored in the fmt package
go run main.go
which will print
Hello World!
to the screen. Congratulations! You ran your very first Go program!