2. Hello World

#golang #helloworld

To make sure that everything is running as expected let's write a quick "hello world" program.

Create a new folder where the project will live and run the following command:

go mod init helloWorld

Running the command will create the go.mod file.

We then have to create a main.go file in the same directory.

The hello world code is shown below:

main.go
package main

import "fmt"

func main() {
	fmt.Println("Hello World")

}

To simply run the code, navigate to the same directory as main.go and execute:

go run .

To build it as a stand alone executable simply run

go build .

The beauty of go unlike other languages is that it will figure out all dependencies and packages used. No need to download them separately.

Last updated