From go-agent-skills
Go coding standards and style conventions grounded in Effective Go, Go Code Review Comments, and production-proven idioms. Use when writing or reviewing Go code, enforcing naming conventions, import ordering, variable declarations, struct initialization, or formatting rules. Trigger examples: "check Go style", "fix formatting", "review naming", "Go conventions". Do NOT use for architecture decisions, concurrency patterns, or performance tuning — use go-architecture-review, go-concurrency-review, or go-performance-review instead.
How this skill is triggered — by the user, by Claude, or both
Slash command
/go-agent-skills:go-coding-standardsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Idiomatic Go conventions grounded in Effective Go, Go Code Review Comments, and production-proven idioms.
Idiomatic Go conventions grounded in Effective Go, Go Code Review Comments, and production-proven idioms.
All code MUST pass goimports, go vet, and staticcheck (or golangci-lint run) without errors.
Group imports in this order, separated by blank lines:
import (
// 1. Standard library
"context"
"fmt"
"net/http"
// 2. External packages
"github.com/gorilla/mux"
"log/slog"
// 3. Internal/project packages
"github.com/myorg/myproject/internal/service"
)
NEVER use dot imports. Use aliasing only to resolve conflicts.
util, common, helpers, misc, base.Name(), NOT GetName(). Setters: use SetName().NewFoo() returns *Foo. If only one type in package: New().i, n, err, ctx.userCount, retryTimeout._: var _defaultTimeout = 5 * time.Second.error, len, cap, new, make, close).-er suffix (Reader, Writer, Closer).Use var for top-level declarations. Do NOT specify type when it matches the expression:
// ✅ Good
var _defaultPort = 8080
var _logger = slog.Default()
// ❌ Bad — redundant type
var _defaultPort int = 8080
:= for local variables.var only when zero-value initialization is intentional and meaningful.// ✅ Good — zero value is meaningful
var buf bytes.Buffer
// ✅ Good — short declaration
name := getUserName()
ALWAYS use field names. Never rely on positional initialization:
// ✅ Good
user := User{
Name: "Alice",
Email: "[email protected]",
Age: 30,
}
// ❌ Bad — positional, breaks on field reordering
user := User{"Alice", "[email protected]", 30}
Omit zero-value fields unless clarity requires them:
// ✅ Good — zero values omitted
user := User{
Name: "Alice",
}
Handle errors and special cases first with early returns. Reduce indentation levels:
// ✅ Good — early return
func process(data []Item) error {
for _, v := range data {
if !v.IsValid() {
log.Printf("invalid item: %v", v)
continue
}
if err := v.Process(); err != nil {
return err
}
v.Send()
}
return nil
}
Eliminate unnecessary else blocks:
// ✅ Good
a := 10
if condition {
a = 20
}
// ❌ Bad
var a int
if condition {
a = 20
} else {
a = 10
}
Group related declarations:
const (
_defaultPort = 8080
_defaultTimeout = 30 * time.Second
)
var (
_validTypes = map[string]bool{"json": true, "xml": true}
_defaultUser = User{Name: "guest"}
)
Function ordering within a file:
New() / constructor functionsReceiver methods should appear immediately after the type declaration.
Soft limit of 99 characters. Break long function signatures:
func (s *Store) CreateUser(
ctx context.Context,
name string,
email string,
opts ...CreateOption,
) (*User, error) {
Use defer for cleanup. It makes intent clear at the point of acquisition:
mu.Lock()
defer mu.Unlock()
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
Start enums at 1 (or use explicit sentinel) so zero-value signals "unset":
type Status int
const (
StatusUnknown Status = iota
StatusActive
StatusInactive
)
time Package Properlytime.Duration for durations, NOT raw integers.time.Time for instants. Use time.Since(start) instead of time.Now().Sub(start).int or float64 and convert internally.// ✅ Good
func poll(interval time.Duration) { ... }
poll(10 * time.Second)
// ❌ Bad
func poll(intervalSecs int) { ... }
poll(10)
Before considering code complete:
goimports runs cleango vet ./... passesgolangci-lint run passes (if configured)npx claudepluginhub eduardo-sl/go-agent-skillsGo language conventions, idioms, and toolchain. Invoke when task involves any interaction with Go code — writing, reviewing, refactoring, debugging, or understanding Go projects.
Guides Go code style conventions: line length and breaking, variable declarations, control flow clarity, and when comments help or hurt. Use when writing or reviewing Go code.