Go interview questions usually test five areas: language basics, concurrency with goroutines and channels, error handling, interfaces and generics, and tooling such as modules and testing. The answers below reflect current Go (1.22 and later), including generics, errors.Is and errors.As, context, log/slog, and per-iteration loop variables.
Go was designed at Google by Robert Griesemer, Rob Pike and Ken Thompson, started in 2007 and announced publicly in 2009. Version 1.0 shipped in 2012 and the Go 1 compatibility promise still holds, which is why old Go code keeps compiling.
Why was Go created? Google needed a language with fast compilation, simple syntax, built-in concurrency and easy deployment. Go compiles to a single static binary, has garbage collection, and keeps the feature set small on purpose.
How does Go differ from Java, C++ or Python?
| Area | Go | Typical comparison |
|---|---|---|
| Compilation | Compiled to a native static binary, very fast builds | Java needs a JVM, Python is interpreted |
| Concurrency | Goroutines and channels in the language | Threads and locks in Java or C++ |
| Typing | Static, with type inference and generics (since 1.18) | Python is dynamic |
| Inheritance | None, composition and interfaces instead | Java and C++ use class inheritance |
| Memory | Garbage collected, no manual free | C++ is manual or RAII |
| Errors | Returned as values, no exceptions | Java and Python throw exceptions |
What are the zero values? Every variable is initialised: 0 for numbers, false for booleans, "" for strings, and nil for pointers, slices, maps, channels, functions and interfaces.
What is the difference between an array and a slice? An array has a fixed length that is part of its type ([3]int). A slice is a small header (pointer, length, capacity) over an array and can grow with append.
A goroutine is a function running concurrently, scheduled by the Go runtime onto OS threads. Goroutines start with a small stack that grows as needed, so programs can run very large numbers of them.
A channel is a typed conduit for passing values between goroutines. Unbuffered channels synchronise sender and receiver; buffered channels allow a limited number of values to queue.
This is a worker pool: three workers read from jobs, a producer closes it when done, and sync.WaitGroup closes results once every worker has finished.
sync.Mutex or sync/atomic to protect shared state, and go test -race to detect data races.select to wait on several channels, including a timeout or ctx.Done().context.Context as the first parameter to cancel work and carry deadlines.Go functions return an error as the last value, and callers check it explicitly. Wrap errors with %w to add context while keeping the original inspectable.
Use errors.Is to compare against a sentinel error and errors.As to extract a specific error type. panic and recover exist, but they are for unrecoverable situations, not normal control flow. defer runs a call when the surrounding function returns, which makes it the standard tool for cleanup.
Interfaces are satisfied implicitly: any type with the right methods implements the interface, with no implements keyword. Keep interfaces small and define them where they are used.
Generics arrived in Go 1.18. Use them for reusable containers and helpers such as slices.Sort and maps.Keys from the standard library, and prefer plain interfaces when behaviour differs per type.
A pointer receiver (func (r *Rect)) lets a method modify the value and avoids copying large structs. An interface holding a nil pointer is not itself nil, a classic trick question.
go mod init, go mod tidy, and the go.mod and go.sum files. The old GOPATH workflow and tools such as dep are obsolete._test.go files and use the testing package. Table-driven tests are the idiom, and go test -cover reports coverage. Fuzzing is built in since Go 1.18.net/http), JSON (encoding/json), structured logging (log/slog, Go 1.21), and file I/O (os, io).net/http router, for example mux.HandleFunc("GET /items/{id}", handler).Go uses a concurrent, non-generational, tri-color mark-and-sweep garbage collector designed for low pause times. It runs alongside your code and is tuned mainly with GOGC (target heap growth) and GOMEMLIMIT (a soft memory limit, since Go 1.19).
The compiler uses escape analysis to decide whether a value lives on the stack or the heap. Returning a pointer to a local variable is safe because the value escapes to the heap. You can inspect decisions with go build -gcflags=-m.
Go has types with methods and interfaces, but no classes or inheritance. You reuse behaviour by embedding structs and by programming against interfaces.
Use channels to pass ownership of data or coordinate goroutines, and a mutex to protect a shared structure such as a cache. Choosing the simpler of the two is fine.
No. Errors are ordinary values returned from functions. panic exists for programming errors and unrecoverable states.
new and make?new(T) allocates a zeroed T and returns *T. make creates slices, maps and channels and returns an initialised value of that type.
Prepare Go interviews by mastering slices and maps, goroutines with channels and context, error wrapping with errors.Is and errors.As, small interfaces, and generics. Add practical knowledge of modules, table-driven tests and the race detector, and be ready to write short programs like the worker pool above.