
Go Control Flow
This covers the full spectrum of Go's control flow constructs: if with initialization, guard clauses with early returns, the three forms of for loops, range iteration, switch statements, and the blank identifier. The guide is opinionated about indentation (keep success paths unindented, bury errors not normal flow) and warns about the shadowing trap with short declarations inside blocks. It links out to separate references for switch patterns and blank identifier details, and explicitly excludes error flow patterns, sending you to go-error-handling instead. The quick reference table at the end is a solid cheat sheet for the non-obvious bits like labeled breaks and compile-time interface checks.
- skills.sh installs
- 1.3K
- GitHub stars
- 193
- last updated
- Aug 21, 2026
Install
$ npx -y skills add cxuu/golang-skills --skill go-control-flow --agent claude-codeInstalls into .claude/skills of the current project.
Files
Go Control Flow
Resource Routing
references/SWITCH-PATTERNS.md- Read when using switch statements, type switches, fallthrough, or labeled breaks.references/BLANK-IDENTIFIER.md- Read when using_, blank imports, unused compile-time assertions, or intentional discards.
If with Initialization
if and switch accept an optional initialization statement. Use it to scope
variables to the conditional block:
if err := file.Chmod(0664); err != nil {
log.Print(err)
return err
}
If you need the variable beyond a few lines after the if, declare it
separately and use a standard if instead:
x, err := f()
if err != nil {
return err
}
// lots of code that uses x
Indent Error Flow (Guard Clauses)
When an if body ends with break, continue, goto, or return, omit the
unnecessary else. Keep the success path unindented:
f, err := os.Open(name)
if err != nil {
return err
}
d, err := f.Stat()
if err != nil {
f.Close()
return err
}
codeUsing(f, d)
Never bury normal flow inside an else when the if already returns.
Redeclaration and Reassignment
Sponsors
Details
- Repository
- github.com/cxuu/golang-skills
- Categories
- Documentation, Debugging, Go
- First seen
- May 16, 2026
More from cxuu/golang-skills
All 20- Go Logging1.1K
- Go Functions1.1K
- Go Generics1.1K
- Go Declarations1.1K
- Go Code Review1.8K
- Go Testing1.4K
- Go Error Handling1.3K
- Go Linting1.3K
- Go Concurrency1.3K
- Go Interfaces1.3K
- Go Documentation1.3K
- Go Style Core1.3K
- Go Performance1.3K
- Go Context1.3K
- Go Naming1.3K
- Go Defensive1.3K
- Go Packages1.3K
- Go Data Structures1.3K
- Go Functional Options1.3K