Go Fundamentals

Lesson 1 of 8

Hello, Go

Go (often called Golang) was built at Google to be simple, fast to compile, and easy to run at scale, it deliberately has a small feature set compared to languages like C++ or Java, that's a design goal, not a limitation.

Your first program

package main

import "fmt"

func main() {
    fmt.Println("Hello, Kodstigen!")
}
  • Every Go file belongs to a package, package main marks this one as an executable program's entry point (as opposed to a reusable library package).
  • import "fmt" brings in the formatting/printing package, Go's standard library is organized into small, focused packages like this.
  • func main() is where execution starts, no class wrapper needed, unlike Java.

Compiling and running

go run main.go     # compile and run in one step, good for development
go build main.go   # produce a standalone binary called main (or main.exe)
./main

Go compiles to a single, statically-linked binary with no external runtime required, you can copy that one file to another machine and run it, nothing else needs to be installed.

TIP

Go ships an opinionated formatter, gofmt, and the community treats consistent formatting as non-negotiable. Run gofmt -w main.go and never argue about tabs vs. spaces again.

📝 Hello, Go Quiz

Passing score: 70%
  1. 1.What does "go build" produce?

  2. 2.Go requires main to be defined inside a class, similar to Java.

  3. 3.The command that compiles and runs a Go file in a single step is: go ____ main.go