
Go Control Flow
Go conditionals, loops, and switch statements with guard clauses, scoped initialization, and blank identifier patterns.
- skills.sh installs
- 1.3K
- GitHub stars
- 196
- last updated
- Aug 21, 2026
Own this skill? Claim it
What it does
- Covers
ifwith initialization, early-return guard clauses, and thefor,range, andswitchforms in Go - Includes
references/SWITCH-PATTERNS.mdfor type switches,fallthrough, and labeled breaks, plusreferences/BLANK-IDENTIFIER.mdfor discards and imports - Warns about
:=shadowing in inner scopes and shows when=should be used to avoid silent bugs - Designed for Go code where error handling is left to the go-error-handling skill and interface checks to go-interfaces
Install
$ npx -y skills add cxuu/golang-skills --skill go-control-flow -yInstalls into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.
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
Details
- Repository
- github.com/cxuu/golang-skills
- Category
- 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.4K
- Go Concurrency1.4K
- Go Linting1.4K
- Go Interfaces1.4K
- Go Documentation1.3K
- Go Style Core1.3K
- Go Performance1.3K
- Go Context1.3K
- Go Naming1.3K
- Go Defensive1.3K
- Go Packages1.3K
- Go Functional Options1.3K
- Go Data Structures1.3K
Similar to Go Control Flow
More Go
go-declarationscxuu/golang-skills1.1K installsGo declaration style guide covering var vs :=, iota enums, scope, struct and map initialization, and literal formatting.
go-style-corecxuu/golang-skills1.3K installsCore Go style guidance covering clarity-first priorities, gofmt, early returns, and semicolon rules.
golang-design-patternssamber/cc-skills-golang44.3K installsIdiomatic Go design patterns covering constructors, error flow, lifecycle, and architecture choices for production code.
golang-safetysamber/cc-skills-golang42.7K installsDefensive Go coding guidance against nil panics, append aliasing, silent truncation, and defer-in-loop leaks.
go-code-reviewexistential-birds/beagle205 installsStructured Go review skill that checks idiomatic patterns, error handling, concurrency safety, and version-gated advice from go.mod.