Questions
Go questions
Choose a question page, learn the concept, then test your understanding with a quiz.
How to Run Specific Go Tests: File vs Test Name in Go
Learn how to run specific Go tests using go test, -run, and package rules. Understand why Go targets packages, not test files.
How to Run a Go Program with Multiple Files in the Same Package
Learn how to split a Go main package across multiple files and run it correctly with go run, packages, and project structure basics.
How to Seed a Random Number Generator Properly in Go
Learn how to seed Go's random number generator correctly, avoid repeated values, and generate random strings efficiently.
How to Send JSON in a POST Request in Go
Learn how to send JSON in a POST request in Go, including dynamic JSON bodies, headers, marshaling, and common mistakes.
How to Set Default Values in Go Structs
Learn how default values work in Go structs, common patterns for custom defaults, constructors, and practical examples for clean Go code.
How to Set GOPATH on Ubuntu in Go
Learn what GOPATH is, where to set it on Ubuntu, which shell file to edit, and how it affects go get and Go projects.
How to Set Headers in an HTTP GET Request in Go
Learn how to set custom headers on an HTTP GET request in Go using net/http, with examples, mistakes to avoid, and practical patterns.
How to Sort a Slice of Structs by Field in Go
Learn the simplest ways to sort a slice of structs by a field in Go, including sort.Slice, custom comparisons, and common mistakes.
How to Trim Leading and Trailing Whitespace in Go Strings
Learn how to trim leading and trailing whitespace in Go using strings.TrimSpace, with examples, mistakes, and real-world use cases.
How to Use a Specific Git Commit in go.mod for a Go Module Dependency
Learn how to point a Go module dependency to a specific commit in go.mod using pseudo-versions, go get, and replace directives.
How to Use go get with Private Repositories in Go
Learn the proper way to use go get with private Git repositories in Go, including SSH setup, GOPRIVATE, and common mistakes.
How to Write Multiline Strings in Go
Learn how multiline strings work in Go using raw string literals and escaped strings, with examples, pitfalls, and practical use cases.
Idiomatic Enums in Go: Representing Fixed Values Like DNA Bases
Learn the idiomatic way to represent enums in Go using typed constants and iota, with examples for DNA bases like A, C, T, and G.
Lowercase JSON Key Names with json.Marshal in Go
Learn how to produce lowercase JSON keys in Go using struct tags, custom marshaling, and practical patterns with encoding/json.
Maximum Value of uint in Go: Finding Min and Max Safely
Learn how to get the maximum uint value in Go and use it safely when computing min and max values in loops.
Optional Parameters in Go: How to Handle Missing Arguments
Learn how Go handles optional parameters, why function overloading is not supported, and common patterns to simulate optional arguments.
Passing Functions as Parameters in Go
Learn how to pass functions as parameters in Go, use callbacks, and understand function types with clear examples and common mistakes.
Repeating Tasks at Intervals in Go with time.Ticker and Timers
Learn how to run repetitive tasks at intervals in Go using time.Ticker, timers, goroutines, and clean stop patterns.
Stack vs Heap Allocation in Go: Structs, Escape Analysis, and Garbage Collection
Learn how Go decides stack vs heap allocation for structs, why returning local addresses is safe, and how pointers relate to GC.
Struct Tags in Go: What They Are and How They’re Used
Learn what struct tags in Go are, how reflection reads them, and how packages like json, xml, db, and validation use them in real projects.