Programming languages

Go

A simple compiled language with built-in concurrency for network services and infrastructure.

What it is

Robert Griesemer, Rob Pike and Ken Thompson designed Go at Google. It went public in 2009. It is statically typed, compiled and garbage-collected.

The design is deliberately minimal: a small syntax, fast compilation, a single dependency-free binary. Concurrency is built in with goroutines and channels. The standard toolchain includes gofmt, testing and a profiler.

Docker, Kubernetes, Terraform and Prometheus are written in Go. It became the language of cloud infrastructure.

Use it when

  • Network services, APIs and microservices with high concurrency.
  • CLI tools and DevOps tooling as a single static binary.
  • The team wants a simple language with a low barrier to entry and predictable code.

Avoid it when

  • Complex domain logic that needs rich abstractions: Go is deliberately limited.
  • Frontend, mobile UI and scientific computing.
  • Hard real-time needs with no GC pauses: use Rust or C++.

Key concepts

Goroutine
A lightweight thread managed by the Go runtime. Started with the go keyword, you can create thousands.
Channel
A typed queue for passing data between goroutines. The idea: do not share memory, communicate over channels.
Interface
Satisfied implicitly: if a type has the needed methods it implements the interface, no implements required.
Error as value
Errors are returned as ordinary values (val, err := f()), there are no exceptions.
Modules
The go.mod dependency system with versioning.

Example

Three goroutines and waiting for them with a WaitGroup.

Cheat sheet

Go cheat sheet
Command or codeWhat it does
go mod init example.com/appCreates a module
go run .Runs the program
go build ./...Builds all packages
go test ./... -raceTests with the race detector
go get github.com/pkg/name@latestAdds a dependency
go mod tidyTidies and syncs dependencies
go func() { ... }()Starts a goroutine
ch := make(chan int, 10)Buffered channel
if err != nil { return err }The usual error handling
defer f.Close()Deferred call that runs when the function returns

How to learn it

  1. Install Go and go through the official Tour of Go.
  2. Learn types, slices, maps, structs and methods.
  3. Understand interfaces and error handling by returning error values.
  4. Study goroutines, channels and the sync and context packages.
  5. Write an HTTP server using only the net/http standard library.
  6. Add tests with go test and table driven cases.
  7. Connect a database and build a small REST API.
  8. Read Effective Go and look at the Gin framework.

Interview questions

  1. 1. What is a goroutine and how does it differ from an OS thread?

    A goroutine is a lightweight task managed by the Go scheduler. It starts with a small stack (a few KB) and is multiplexed onto a few OS threads. That is why you can run hundreds of thousands of them.

  2. 2. How does Go handle errors?

    A function returns the error as its last value, and the caller checks if err != nil. It is explicit with no hidden control flow, if verbose. Wrapping uses fmt.Errorf with %w.

  3. 3. What is context for?

    context.Context carries cancellation, deadlines and request values through a call chain. That lets long operations stop when the client disconnects.

  4. 4. Does Go have inheritance?

    No. It has composition (embedded structs) and interfaces that are satisfied implicitly.

Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).