con un clic
golang
// Go coding standards and conventions for this project. Apply when writing, reviewing, or refactoring any Go source file.
// Go coding standards and conventions for this project. Apply when writing, reviewing, or refactoring any Go source file.
| name | golang |
| description | Go coding standards and conventions for this project. Apply when writing, reviewing, or refactoring any Go source file. |
| triggers | ["on_commit"] |
Follow idiomatic Go practices and community standards when writing Go code. These instructions are based on Effective Go, Go Code Review Comments, and Google's Go Style Guide.
else statements - use early returns, continue, or break instead_ characters, hyphens, or mixedCapsutil, common, or base_ charactershttp.HTTPServer, prefer http.Server)Reader, Writer, Formatter)Read → Reader)const blocksgofmt to format codegoimports to manage imports automatically//) for most comments/* */) sparingly, mainly for package documentation_ unless you have a good reason (document why)fmt.Errorf with %w verberrlog package for logginglog.Error(err)log package handle itdefer log.Trace(time.Now(), args)
where args are the function arguments at the start of the function.else statements - they create unnecessary nesting and reduce readabilitycontinue in loops to skip to the next iteration instead of nestingbreak to exit loops early instead of complex conditional logic❌ BAD - Don't do this:
func processEntry(entry *Entry) string {
if entry.Expired() {
return "expired"
} else {
if entry.TTL < 0 {
return "never expires"
} else {
return fmt.Sprintf("expires at %s", time.Unix(entry.Timestamp, 0))
}
}
}
✅ GOOD - Do this instead:
func processEntry(entry *Entry) string {
if entry.Expired() {
return "expired"
}
if entry.TTL < 0 {
return "never expires"
}
return fmt.Sprintf("expires at %s", time.Unix(entry.Timestamp, 0))
}
❌ BAD - Nested loop logic:
for _, item := range items {
if item.IsValid() {
if item.ShouldProcess() {
// complex processing logic
}
}
}
✅ GOOD - Early continue:
for _, item := range items {
if !item.IsValid() {
continue
}
if !item.ShouldProcess() {
continue
}
// complex processing logic (happy path)
}
go.mod and go.sum)go mod tidy to clean up unused dependenciessync.WaitGroup or channels to wait for goroutinesselect for non-blocking operationssync.Mutex for protecting shared statesync.RWMutex when you have many readerssync.Once for one-time initializationerrors.New for simple static errorsfmt.Errorf for errors with runtime valueserrors.Is and errors.As for error checkingsync.Pool)pprof)testing.B for benchmarks_test package suffix for black-box testing_test.go suffixTestFunctionNameScenariot.Run for better organizationtestify/assert and testify/require for assertionslibtime for the time package.t.Helper()testing.TB interface for functions used in tests and benchmarkst.Cleanup()When a test mutates package-level variables (resolvers, loggers, clocks, time.Local, etc.),
save the original value into a local variable and restore it via t.Cleanup. Never restore to a
hardcoded value; you would overwrite whatever state preceded your test.
// ✅ CORRECT: save original, restore original
origResolver := myPackageResolver
t.Cleanup(func() { myPackageResolver = origResolver })
myPackageResolver = fakeResolver
origLocal := time.Local
t.Cleanup(func() { time.Local = origLocal })
time.Local = time.UTC
// ❌ WRONG: restores to a hardcoded value instead of the pre-test value
defer func() { time.Local = time.FixedZone("UTC", 0) }()
go fmt: Format codego vet: Find suspicious constructsgolint or golangci-lint: Additional lintinggo test: Run testsgo mod: Manage dependenciesgo generate: Code generationREQUIRED BEFORE EVERY COMMIT. Run the following commands in sequence after any Go code change. Commit after all pass with zero errors. Never skip this step; these linters catch real bugs and style violations that will be flagged in CI or code review.
Code Modernization: Apply modern Go best practices; this rewrites files in place
modernize --fix "./..."
modernizemodifies source files (e.g. replacingstrings.Splitwithstrings.SplitSeqfor Go 1.24+ range loops). Always stage its changes and include them in the same commit as your feature code.
Field Alignment: Optimize struct field ordering for memory efficiency; this rewrites files in place
fieldalignment --fix "./..."
Warning:
fieldalignmentrewrites struct field order. Any inline struct literals that use positional (unnamed) field initialization (common in table-driven test files) will break after the reorder. Always use named fields in struct literals (e.g.{Case: "foo", Now: t}) so that the order of fields in the struct definition does not matter.
Dependency Management: Clean up and organize module dependencies
go mod tidy
Formatting and Linting: Ensure code follows standards (must report zero errors)
gofmt -w .
golangci-lint run
After steps 1 through 3, always run git diff to review auto-applied changes before staging them.
All four steps must complete with zero errors before the commit is created.
_unix.go, _windows.go, _darwin.go)If you add or modify a file with a platform-specific suffix, also cross-compile to catch issues the local OS linter skips. On Windows, run:
$env:GOOS = "linux"; go build ./...; $env:GOOS = ""
On Linux/macOS, run:
GOOS=windows go build ./...
This catches import mismatches, missing symbols, and linter rules (like modernize
strings.SplitSeq) that apply on the non-host platform.
These rules frequently fire on new code and are quick to resolve before linting:
| Linter | Trigger | Fix |
|---|---|---|
goconst | Same string literal occurs 3+ times | Extract to a named const |
gofmt | Incorrect indentation or comment spacing | Run gofmt -w .; it fixes automatically |
dupl | Two functions/test cases with near-identical structure | Add //nolint:dupl with a brief reason comment |
modernize | strings.Split used in a for range (Go 1.24+) | Run modernize --fix "./..." (auto-fixes) |
interface{} or any)Autonomously optimize any Claude Code skill by running it repeatedly, scoring outputs against binary evals, mutating the prompt, and keeping improvements. Based on Karpathy's autoresearch methodology. Use when: optimize this skill, improve this skill, run autoresearch on, make this skill better, self-improve skill, benchmark skill, eval my skill, run evals on. Outputs: an improved SKILL.md, a results log, and a changelog of every mutation tried.
Workflow for generating conventional commit messages following the Conventional Commits specification. MUST be invoked every time a commit is created. Guides construction of standardized commit messages with correct type, scope, description, body, and footer.
Enforce Vale prose checks on any user-facing text the agent creates or edits — comments, documentation, status messages, release notes, READMEs, or any explanatory content that users will read. Always use this skill when producing or changing prose, even when Vale is not explicitly requested.
Markdown formatting rules for this project. Apply when writing or editing any .md or .mdx file, including documentation and website content.
PowerShell cmdlet conventions for this project. Apply when writing or reviewing any .ps1 or module file.