Claude-skill-registry go-google-style-decisions
Expertise in Go programming decisions according to the Google Go Style Guide. Focuses on specific choices for naming, error handling, and language usage.
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/go-google-style-decisions" ~/.claude/skills/majiayu000-claude-skill-registry-go-google-style-decisions && rm -rf "$T"
manifest:
skills/data/go-google-style-decisions/SKILL.mdsource content
go-google-style-decisions
This skill provides expert guidance on the "Decisions" portion of the Google Go Style Guide. It focuses on the specific choices and trade-offs made to ensure consistency, readability, and maintainability across large Go codebases.
Core Mandates
- Clarity over Conciseness: While Go favors brevity, never sacrifice clarity.
- Consistency is Key: Adhere to established patterns in the codebase.
- Idiomaticity: Follow Go-specific patterns (e.g., error handling, interface usage).
- No Underscores: Avoid underscores in names except in specifically allowed cases (tests, generated code).
Developer Workflow
- Design: Plan APIs following the "Least Mechanism" principle.
- Implement: Write code adhering to the style decisions detailed below.
- Lint: Use
orgolangci-lint
to catch common style violations.go vet - Test: Include runnable examples in
files for public APIs._test.go - Review: Ensure changes align with the "Core Principles" of clarity and consistency.
Detailed Guidance
For the complete guide, consult references/decisions.md.
1. Naming Conventions
- Underscores: Do not use underscores in Go names (e.g.,
orpkg_name
).var_name- Exceptions:
files, generated code, and low-level interop._test.go
- Exceptions:
- Package Names:
- Short, lowercase, single word. No
orutil
.common - Avoid common variable names (e.g.,
as a package name ifuser
is a common variable).user
- Short, lowercase, single word. No
- Receiver Names:
- Short (1-2 letters).
- Consistently used throughout the type's methods.
- Usually an abbreviation of the type (e.g.,
forc
).Client
- Constant Names:
- Use
(e.g.,MixedCaps
,ExportedConst
).internalConst - Do NOT use
orALL_CAPS
.kPrefix
- Use
- Initialisms:
- Maintain consistent casing (e.g.,
,HTTPClient
,urlPath
).XMLParser
- Maintain consistent casing (e.g.,
- Getters:
- Omit
prefix (e.g., useGet
instead ofobj.Field()
).obj.GetField() - Use
only if the method is truly "getting" something that isn't a simple field (e.g.,Get
).GetURL
- Omit
- Variable Names:
- Length should be proportional to scope. Short names for small scopes (e.g.,
in a loop), more descriptive names for larger scopes.i - Omit types from names (e.g.,
instead ofusers
).userSlice
- Length should be proportional to scope. Short names for small scopes (e.g.,
2. Commentary
- Line Length: Aim for ~80 characters. Wrap long comments.
- Doc Comments: Every top-level exported name MUST have a doc comment.
- Must start with the name of the object.
- Must be a complete sentence.
- Examples: Provide
functions in test files to document public APIs.ExampleXxx
3. Error Handling
- Error as Last Return: Always return
as the final value.error - Returning Nil: Return
for the error value on success.nil - Error Interfaces: Exported functions should return the
interface, not a concrete type.error - Error Strings:
- No capitalization (unless proper nouns/acronyms).
- No trailing punctuation.
- Indentation: Handle errors early and return/continue. Keep the "happy path" at the minimal level of indentation.
- No In-band Errors: Do not use special values (like
) to signal errors. Use-1
or(value, error)
.(value, ok)
4. Language Constructs
- Composite Literals: Use them for struct initialization. Always specify field names when the struct is from another package.
- Nil Slices: Prefer
(nil slice) overvar s []int
(empty slice).s := []int{}- Avoid APIs that distinguish between nil and empty slices.
- Braces:
- Closing braces should align with the opening statement.
- Avoid "cuddling" (e.g.,
is fine, but don't over-compact).if err != nil { ... } else { ... }
- Function Formatting: Keep signatures on one line if possible. If they must wrap, indent the arguments.
5. Panic and Recovery
- Avoid Panic: Do not use
for normal error handling.panic - Exceptional Only: Use
only for truly unrecoverable states (e.g., internal invariant failure).panic - Program Termination: Use
orlog.Exit
(which callslog.Fatal
) only inos.Exit
ormain
functions.init - MustXYZ: Helper functions that terminate the program on failure should be prefixed with
(e.g.,Must
).template.Must
6. Copying
- Structs with Locks: Be extremely careful copying structs that contain
or other synchronization primitives.sync.Mutex - Pointer Receivers: If a type has methods with pointer receivers, avoid copying values of that type.