Practice / go

Go practice

Every Go exercise, built from a topic you can open beside it.

106 exercises runs offline
go Quiz new Which declarations make a Go package directly executable? Quiz beginner 1 min · from checkpoint-1 go Quiz new How does Go make an identifier accessible from another package? Quiz beginner 1 min · from checkpoint-1 go Fill in new Complete the compile-time assertion for a pointer type: `var _ Notifier = ______` Fill in advanced 1 min · from checkpoint-1 go Fill in new Name the set that determines whether `T` or `*T` satisfies an interface Fill in intermediate 1 min · from checkpoint-1 go Fill in new Name the file at a module root that declares the module path and dependency requirements Fill in beginner 1 min · from checkpoint-1 go Quiz new A struct containing a slice is assigned to another variable. Which statement is correct? Quiz intermediate 1 min · from checkpoint-1 go Quiz new A nil `*ParseError` is stored in a variable of type `error`. What is true? Quiz advanced 1 min · from checkpoint-1 go Fill in new Name the value automatically assigned to a declared variable that has no explicit initial… Fill in intermediate 1 min · from checkpoint-1 go Quiz new A function appends to a slice. Which rule keeps the result correct whether or not a new b… Quiz beginner 1 min · from checkpoint-2 go Quiz new Which statement about deferred calls is correct? Quiz advanced 1 min · from checkpoint-2 go Quiz new A sentinel has been wrapped twice. Which check preserves the caller contract? Quiz advanced 1 min · from checkpoint-2 go Quiz new A map may legitimately store zero. How should code distinguish an absent key from a prese… Quiz intermediate 1 min · from checkpoint-2 go Fill in new Give the runtime failure message produced by assigning an entry to a nil map Fill in beginner 1 min · from checkpoint-2 go Fill in new Name the built-in function that can stop panic unwinding when called directly by a deferr… Fill in advanced 1 min · from checkpoint-2 go Fill in new Which token before a constraint term such as `int` also admits named types whose underlyi… Fill in intermediate 1 min · from checkpoint-2 go Fill in new Which `fmt.Errorf` formatting verb adds context while preserving an error for later unwra… Fill in intermediate 1 min · from checkpoint-2 go Fill in new Name the flow-control effect created when a bounded worker pool makes producers wait inst… Fill in advanced 1 min · from checkpoint-3 go Fill in new A function calls `context.WithTimeout`. Name the returned function it must call to releas… Fill in intermediate 1 min · from checkpoint-3 go Quiz new Which worker-loop design responds promptly when its request is cancelled? Quiz advanced 1 min · from checkpoint-3 go Fill in new In `value, ok := <-ch`, which result becomes false after a closed channel has been draine… Fill in beginner 1 min · from checkpoint-3 go Quiz new A service struct contains a `sync.Mutex` that has already been used. Which change is safe? Quiz intermediate 1 min · from checkpoint-3 go Quiz new How does a `select` treat a send or receive case whose channel is nil? Quiz intermediate 1 min · from checkpoint-3 go Quiz new What must happen before a send on an unbuffered channel can complete? Quiz beginner 1 min · from checkpoint-3 go Fill in new Name the `sync` type used to wait until a known group of goroutines has called `Done` Fill in intermediate 1 min · from checkpoint-3 go Fill in new Name the `bufio.Writer` method that pushes buffered bytes to the underlying writer Fill in beginner 1 min · from checkpoint-4 go Quiz new Which action implements a bounded graceful shutdown for an `http.Server`? Quiz intermediate 1 min · from checkpoint-4 go Fill in new Name the `http.ResponseWriter` method after which changing ordinary response headers is t… Fill in intermediate 1 min · from checkpoint-4 go Quiz new An HTTP API must reject misspelled JSON fields instead of silently ignoring them. Which d… Quiz intermediate 1 min · from checkpoint-4 go Quiz new Which review rule preserves a structured logging contract at an authentication boundary? Quiz advanced 1 min · from checkpoint-4 go Fill in new Name the sentinel returned by `QueryRow(...).Scan(...)` when a query produces no row Fill in advanced 1 min · from checkpoint-4 go Quiz new An `io.Reader` returns `n > 0` and `err == io.EOF` in the same call. What should the call… Quiz beginner 1 min · from checkpoint-4 go Quiz new A repository must bind a slice safely into an SQL `IN` clause and support PostgreSQL plac… Quiz advanced 1 min · from checkpoint-4 go Fill in new Which `testing.B` field supplies the iteration count that a benchmark body must use? Fill in intermediate 1 min · from checkpoint-5 go Fill in new Name the fuzz-test method used to add a known input to the seed corpus before calling `Fu… Fill in intermediate 1 min · from checkpoint-5 go Quiz new A shared assertion helper reports failures at its own line instead of the caller. What is… Quiz beginner 1 min · from checkpoint-5 go Fill in new Name the standard command used to inspect a Go CPU or heap profile Fill in advanced 1 min · from checkpoint-5 go Fill in new Which filename suffix makes a Go source file part of the test build? Fill in beginner 1 min · from checkpoint-5 go Quiz new A benchmark performs expensive fixture setup before its measured loop. Which change isola… Quiz advanced 1 min · from checkpoint-5 go Quiz new A service has intermittent scheduler latency between goroutines, but a CPU profile shows … Quiz advanced 1 min · from checkpoint-5 go Quiz new What conclusion is justified after `go vet ./...` succeeds? Quiz intermediate 1 min · from checkpoint-5 go Quiz new Which operation terminates without running deferred calls? Understand defer evaluation and ordering, panic unwinding, and recover's strict boundaries without skipping cleanup or hiding failures. intermediate 1 min · from defer, panic and recover go Predict the output new What does this program print? Understand defer evaluation and ordering, panic unwinding, and recover's strict boundaries without skipping cleanup or hiding failures. beginner 2 min · from defer, panic and recover go Quiz new When can recover stop a panic? Understand defer evaluation and ordering, panic unwinding, and recover's strict boundaries without skipping cleanup or hiding failures. intermediate 1 min · from defer, panic and recover go Review AI code new Review a generated batch exporter Understand defer evaluation and ordering, panic unwinding, and recover's strict boundaries without skipping cleanup or hiding failures. advanced 6 min · from defer, panic and recover go Spot the bug new Spot the bug in batch digest Understand defer evaluation and ordering, panic unwinding, and recover's strict boundaries without skipping cleanup or hiding failures. intermediate 4 min · from defer, panic and recover go Quiz new Given an error chain that may contain *PathError, which use of errors.As is correct? How Go treats errors as values, preserves causes through wrapping, and exposes stable failure contracts without string matching. intermediate 1 min · from Error handling go Quiz new Which statement about errors.Join is correct? How Go treats errors as values, preserves causes through wrapping, and exposes stable failure contracts without string matching. intermediate 1 min · from Error handling go Predict the output new What does this program print? How Go treats errors as values, preserves causes through wrapping, and exposes stable failure contracts without string matching. beginner 2 min · from Error handling go Review AI code new Review a generated session loader How Go treats errors as values, preserves causes through wrapping, and exposes stable failure contracts without string matching. advanced 8 min · from Error handling go Spot the bug new Spot the bug in the typed nil error How Go treats errors as values, preserves causes through wrapping, and exposes stable failure contracts without string matching. intermediate 4 min · from Error handling go Quiz new A package replaces its database but wants callers to keep matching ErrAccountMissing. Whi… Go error wrapping adds context without sacrificing the error identities, types, and fields that callers inspect with errors.Is and errors.As. intermediate 1 min · from Error wrapping go Predict the output new Which three Boolean values does this program print? Go error wrapping adds context without sacrificing the error identities, types, and fields that callers inspect with errors.Is and errors.As. intermediate 2 min · from Error wrapping go Predict the output new What does this program print? Go error wrapping adds context without sacrificing the error identities, types, and fields that callers inspect with errors.Is and errors.As. beginner 2 min · from Error wrapping go Review AI code new Review a generated operation wrapper Go error wrapping adds context without sacrificing the error identities, types, and fields that callers inspect with errors.Is and errors.As. advanced 6 min · from Error wrapping go Spot the bug new Spot the bug in the errors.As target Go error wrapping adds context without sacrificing the error identities, types, and fields that callers inspect with errors.Is and errors.As. intermediate 4 min · from Error wrapping go Predict the output new What does this program print? How packages, declarations, types, functions, and control flow turn Go source files into programs, with the scope and string rules beginners often miss. beginner 2 min · from Go fundamentals go Review AI code new Review a generated limit-summary parser How packages, declarations, types, functions, and control flow turn Go source files into programs, with the scope and string rules beginners often miss. intermediate 8 min · from Go fundamentals go Quiz new When can names already declared in the current block appear on the left of :=? How packages, declarations, types, functions, and control flow turn Go source files into programs, with the scope and string rules beginners often miss. beginner 1 min · from Go fundamentals go Spot the bug new Spot the bug in port selection How packages, declarations, types, functions, and control flow turn Go source files into programs, with the scope and string rules beginners often miss. intermediate 4 min · from Go fundamentals go Quiz new When ranging over a UTF-8 string with for index, value := range text, what are index and … How packages, declarations, types, functions, and control flow turn Go source files into programs, with the scope and string rules beginners often miss. intermediate 1 min · from Go fundamentals go Quiz new In a constraint, what is the difference between int and ~int? Use type parameters, constraints, and type sets to write reusable, type-safe Go, without common named-type, inference, and method mistakes. intermediate 1 min · from Generics go Quiz new A Stack[T] method needs to transform values into a new type U. Which declaration is valid… Use type parameters, constraints, and type sets to write reusable, type-safe Go, without common named-type, inference, and method mistakes. intermediate 1 min · from Generics go Predict the output new What does this program print? Use type parameters, constraints, and type sets to write reusable, type-safe Go, without common named-type, inference, and method mistakes. beginner 2 min · from Generics go Review AI code new Review generated stable deduplication Use type parameters, constraints, and type sets to write reusable, type-safe Go, without common named-type, inference, and method mistakes. advanced 6 min · from Generics go Spot the bug new Spot the bug in the comparable constraint Use type parameters, constraints, and type sets to write reusable, type-safe Go, without common named-type, inference, and method mistakes. beginner 4 min · from Generics go Quiz new Given func (s *Sequence) Next() int, which compile-time assertion is valid? Go interfaces describe behavior with method sets; understand implicit satisfaction, method sets, interface values, and typed nils to design reliable boundaries. beginner 1 min · from Interfaces go Predict the output new Which branch handles the OrderID value? Go interfaces describe behavior with method sets; understand implicit satisfaction, method sets, interface values, and typed nils to design reliable boundaries. intermediate 2 min · from Interfaces go Predict the output new What does this program print? Go interfaces describe behavior with method sets; understand implicit satisfaction, method sets, interface values, and typed nils to design reliable boundaries. intermediate 2 min · from Interfaces go Review AI code new Review generated alert sender Go interfaces describe behavior with method sets; understand implicit satisfaction, method sets, interface values, and typed nils to design reliable boundaries. advanced 6 min · from Interfaces go Spot the bug new Spot the bug in the map[any] lookup Go interfaces describe behavior with method sets; understand implicit satisfaction, method sets, interface values, and typed nils to design reliable boundaries. intermediate 4 min · from Interfaces go Quiz new Which declaration is a valid Go map type? Go maps index values by key; comparability, zero values, sharing, unordered iteration, and concurrency boundaries determine whether their use is correct. beginner 1 min · from Maps go Quiz new Which operation panics when records is a nil map[string]int? Go maps index values by key; comparability, zero values, sharing, unordered iteration, and concurrency boundaries determine whether their use is correct. beginner 1 min · from Maps go Predict the output new What does this program print? Go maps index values by key; comparability, zero values, sharing, unordered iteration, and concurrency boundaries determine whether their use is correct. beginner 2 min · from Maps go Review AI code new Review generated price store Go maps index values by key; comparability, zero values, sharing, unordered iteration, and concurrency boundaries determine whether their use is correct. advanced 6 min · from Maps go Spot the bug new Spot the bug in the map field update Go maps index values by key; comparability, zero values, sharing, unordered iteration, and concurrency boundaries determine whether their use is correct. intermediate 4 min · from Maps go Quiz new Given func (job *Job) Cancel(), which compile-time assertion can succeed for interface{ C… Go methods attach behavior to defined types; receiver semantics, method sets, method values, and promotion determine correct APIs and state changes. intermediate 1 min · from Methods go Predict the output new What does the saved method value print? Go methods attach behavior to defined types; receiver semantics, method sets, method values, and promotion determine correct APIs and state changes. intermediate 2 min · from Methods go Predict the output new What does this program print? Go methods attach behavior to defined types; receiver semantics, method sets, method values, and promotion determine correct APIs and state changes. beginner 2 min · from Methods go Review AI code new Review generated quota tracker Go methods attach behavior to defined types; receiver semantics, method sets, method values, and promotion determine correct APIs and state changes. advanced 6 min · from Methods go Spot the bug new Spot the bug in the map element method Go methods attach behavior to defined types; receiver semantics, method sets, method values, and promotion determine correct APIs and state changes. intermediate 4 min · from Methods go Predict the output new What does this program print? Inspect types and values at runtime with Go's reflect package; handle kinds, settable values, struct tags, nils, and dynamic calls without panics. intermediate 2 min · from Reflection go Review AI code new Review generated settings updater Inspect types and values at runtime with Go's reflect package; handle kinds, settable values, struct tags, nils, and dynamic calls without panics. advanced 6 min · from Reflection go Spot the bug new Spot the bug in the IsNil helper Inspect types and values at runtime with Go's reflect package; handle kinds, settable values, struct tags, nils, and dynamic calls without panics. intermediate 4 min · from Reflection go Quiz new Why would a decoder use StructTag.Lookup("config") instead of Get("config")? Inspect types and values at runtime with Go's reflect package; handle kinds, settable values, struct tags, nils, and dynamic calls without panics. intermediate 1 min · from Reflection go Quiz new Which check is the right default before setting one reflect.Value from another? Inspect types and values at runtime with Go's reflect package; handle kinds, settable values, struct tags, nils, and dynamic calls without panics. intermediate 1 min · from Reflection go Quiz new A method is declared as func (*Worker) Stop(). Which reflected receiver can expose it thr… Go reflection inspects types and values at runtime; understand Type, Value, Kind, settability, and nil boundaries to write safe dynamic code. intermediate 3 min · from reflect.Type and reflect.Value go Quiz new Which check protects Value.Interface() when iterating fields that may be unexported? Go reflection inspects types and values at runtime; understand Type, Value, Kind, settability, and nil boundaries to write safe dynamic code. intermediate 3 min · from reflect.Type and reflect.Value go Predict the output new What does this program print? Go reflection inspects types and values at runtime; understand Type, Value, Kind, settability, and nil boundaries to write safe dynamic code. intermediate 3 min · from reflect.Type and reflect.Value go Review AI code new Review generated settings patcher Go reflection inspects types and values at runtime; understand Type, Value, Kind, settability, and nil boundaries to write safe dynamic code. advanced 12 min · from reflect.Type and reflect.Value go Spot the bug new Spot the bug in the IsNil helper Go reflection inspects types and values at runtime; understand Type, Value, Kind, settability, and nil boundaries to write safe dynamic code. intermediate 4 min · from reflect.Type and reflect.Value go Quiz new What independence does slices.Clone provide for a [][]byte value? Slices are Go's dynamic views over contiguous elements; understanding length, capacity, backing arrays, and append prevents subtle sharing bugs. intermediate 1 min · from Slices go Quiz new Which statement about var items []string and items := []string{} is correct? Slices are Go's dynamic views over contiguous elements; understanding length, capacity, backing arrays, and append prevents subtle sharing bugs. beginner 1 min · from Slices go Predict the output new What does this program print? Slices are Go's dynamic views over contiguous elements; understanding length, capacity, backing arrays, and append prevents subtle sharing bugs. intermediate 2 min · from Slices go Review AI code new Review generated event collector Slices are Go's dynamic views over contiguous elements; understanding length, capacity, backing arrays, and append prevents subtle sharing bugs. advanced 6 min · from Slices go Spot the bug new Spot the bug in the addTag helper Slices are Go's dynamic views over contiguous elements; understanding length, capacity, backing arrays, and append prevents subtle sharing bugs. intermediate 4 min · from Slices go Spot the bug new Spot the bug in the preallocated slice Slices are Go's dynamic views over contiguous elements; understanding length, capacity, backing arrays, and append prevents subtle sharing bugs. beginner 4 min · from Slices go Quiz new Which struct type can be used safely as a map key without a runtime comparability panic? Go structs group related fields into values; zero values, copying, comparability, embedding, and tags determine whether that value behaves as intended. intermediate 1 min · from Structs go Predict the output new What does this program print after copying the struct? Go structs group related fields into values; zero values, copying, comparability, embedding, and tags determine whether that value behaves as intended. beginner 2 min · from Structs go Predict the output new What does this program print? Go structs group related fields into values; zero values, copying, comparability, embedding, and tags determine whether that value behaves as intended. beginner 2 min · from Structs go Review AI code new Review generated profile model Go structs group related fields into values; zero values, copying, comparability, embedding, and tags determine whether that value behaves as intended. advanced 6 min · from Structs go Spot the bug new Spot the bug in the Activate method Go structs group related fields into values; zero values, copying, comparability, embedding, and tags determine whether that value behaves as intended. beginner 4 min · from Structs go Quiz new What must a type satisfy for the constraint `interface { ~string; IsValid() bool }`? Understand Go type-parameter declarations, constraints, type sets, and inference, including named types, generic methods, and comparable edge cases. intermediate 1 min · from Constraints and type sets go Predict the output new What does this program print? Understand Go type-parameter declarations, constraints, type sets, and inference, including named types, generic methods, and comparable edge cases. intermediate 2 min · from Constraints and type sets go Review AI code new Review a generic record index Understand Go type-parameter declarations, constraints, type sets, and inference, including named types, generic methods, and comparable edge cases. advanced 6 min · from Constraints and type sets go Spot the bug new Spot the bug in the any constraint Understand Go type-parameter declarations, constraints, type sets, and inference, including named types, generic methods, and comparable edge cases. beginner 4 min · from Constraints and type sets go Spot the bug new Spot the bug in the Equal call Understand Go type-parameter declarations, constraints, type sets, and inference, including named types, generic methods, and comparable edge cases. advanced 4 min · from Constraints and type sets