Skip to content

Intro to Golang

Select a place where to store your project. If you don’t have one in mind, ~/code/ could be a good start.

Terminal window
cd ~/code/
mkdir todo-app

Creating a go module

You need to select a unique identifier for your project, called a module path, so that people can locate and import code from it. If you have a domain, a common convention is to use a URL that you have control over. I personally use github.com/AlexanderHOtt/<project name>, but if you have a domain you want to use, it could be <project name>.example.com.

Terminal window
go mod init github.com/<github username>/todo-app

You should have a new file named “go.mod” with similar contents below

  • go.mod
go.mod
module github.com/0xdeis/todo-app
go 1.23.0

Hello World

Create a new file named “main.go”.

main.go
package main
import "fmt"
func main() {
fmt.Println("Hello world")
}
  1. All go files must be a part of a package. The default package is “main”.
  2. Go import statements have the package name in double quotes.
  3. The main function is the default entry point of the go program.
Terminal window
go run .
Hello world

Change the program so that it prints your name.

What is the keyword to create function in Go?

  • fn
  • fun
  • func
  • function

What is the function we use to print?

  • Print
  • print
  • Println
  • println