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 mainmarks 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.