Search and navigate

Pages

Start HereRoadmapTutorialsCheatsheetInterview QuestionsResources

Published tutorials

Building a REST API with Go: The Complete TutorialGeneric Functions in Go: Writing Reusable CodeGo Benchmarking: Measuring Performance with testing.BGo Channels: Communication Between GoroutinesGo Constraints: comparable, Ordered and Custom SetsGo Context: Cancellation, Deadlines, and Request ValuesGo HTTP Client: Timeouts, JSON, and Reliable RequestsGo HTTP Middleware: Build a Production ChainGo Interview Questions: 25 Answers That Show UnderstandingGo Mutex: Protecting Shared State from Race ConditionsGo net/http: Build an HTTP Server from ScratchGo select Statement: Multiplexing Channels ExplainedGo Tools You Need for a Reliable Development LoopGo Tutorial: From First Program to Backend FoundationsGo Type Parameters: Syntax and Constraints ExplainedGo Worker Pool Pattern: Bounded Concurrency at ScaleGo's Type System Deep Dive: Static Typing Done RightGolang Compilation and Execution ExplainedGolang File Structure for Modules and ApplicationsGolang Hello World and Your First Go ProgramGolang IDEs: Choose an Editor for Your WorkflowGolang Interfaces: What They Are and How to Use ThemGoroutine Leaks in Go: How to Detect and Prevent ThemGoroutines in Go: Concurrency Without LeaksHow to Download and Install Golang SafelyHow to Learn Golang with a Focused Study PlanIntegration Testing in Go: Testing Real BoundariesJSON in Go: Encoding, Decoding, and ValidationLearn Golang with a Practical Beginner CourseMocking in Go: Test Doubles Without Magicsync.WaitGroup in Go: Coordinating Multiple GoroutinesTable-Driven Tests in Go: The Idiomatic WayTesting in Go: Table Tests, HTTP, Fakes, and CoverageWhat Is Go and How Does a Go Program Work?Why Learn Golang and What Is Go Used For?Writing Unit Tests in Go: A Practical Guide
Open full search and filters →

Golang cheatsheet

Essential Go syntax and production-minded patterns in one scannable reference. Follow the links beneath each example when you need the complete explanation.

Variables and constants

name := "gopher"
var count int
const timeout = 5 * time.Second

Functions and errors

func load(id string) (Item, error) {
  if id == "" { return Item{}, errors.New("id required") }
  return Item{ID: id}, nil
}

Slices and maps

items := []string{"a", "b"}
items = append(items, "c")
counts := map[string]int{"go": 1}

Goroutines and channels

results := make(chan Result)
go func() { results <- work() }()
result := <-results

Context timeout

ctx, cancel := context.WithTimeout(parent, 2*time.Second)
defer cancel()
result, err := fetch(ctx)

Table-driven test

for _, tc := range tests {
  t.Run(tc.name, func(t *testing.T) {
    if got := fn(tc.in); got != tc.want { t.Errorf("got %v", got) }
  })
}

Need more context? Follow the structured Go roadmap →