
Golang Code Style
Train your coding agent to follow Samber-style Go idioms—especially when zero values carry business meaning and `var` vs `:=` signals intent.
Overview
golang-code-style is an agent skill for the Build phase that teaches Go initialization idioms through trapped exercises so agents use `var` and `:=` to signal zero-value intent.
Install
npx skills add https://github.com/samber/cc-skills-golang --skill golang-code-styleWhat is this skill?
- Exercise-driven traps that penalize `:=` for intentional zero values and `var` for clearly non-zero assignments
- Covers Session-style structs with counters, auth flags, errors, timestamps, and slice initialization patterns
- Structured assertions per exercise so agents must satisfy explicit intent signals, not just compiling code
- Aligned with production Go readability: let zero values document defaults instead of noisy `:= 0` / `:= false`
- Part of the cc-skills-golang family for consistent agent behavior across Go repos
- Exercise 1 documents the zero-value-intent trap with multiple structured assertion IDs (e.g. 1.1, 1.2).
Adoption & trust: 4k installs on skills.sh; 2k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your agent writes compiling Go that hides whether fields intentionally start at zero values or were assigned redundant literals like `:= 0`.
Who is it for?
Solo builders maintaining Go APIs or workers who want agents to internalize Samber-style `var` vs `:=` conventions before merging backend PRs.
Skip if: Teams that only need formatting (`gofmt`), generic lint fixes, or non-Go stacks—skip this skill when you are not authoring Go backend code.
When should I use this skill?
When generating or refactoring Go backend files where field initialization intent (`var` vs `:=`) must match business defaults.
What do I get? / Deliverables
Generated Go constructors and locals match explicit intent rules verified by per-exercise assertions, so reviewers can trust zero defaults without reading every initializer.
- Go source files that pass exercise assertions
- Constructors that rely on zero values where intended
Recommended Skills
Journey fit
Go service and CLI code is written in the Build phase; style rules apply while implementing backend packages, not during distribution or ops. Canonical shelf is backend because the skill targets package-level Go structs, constructors, and method locals—not frontend, DevOps, or release mechanics.
How it compares
Use as a procedural style tutor with assertion traps, not as a replacement for golangci-lint or a full code-review skill.
Common Questions / FAQ
Who is golang-code-style for?
Indie and solo developers using AI agents on Go backends who care that zero-value defaults and non-zero initialization read clearly to human reviewers.
When should I use golang-code-style?
During Build/backend implementation when scaffolding structs, constructors, and methods—especially before code review on services where initialization intent matters.
Is golang-code-style safe to install?
It is instructional content with exercise metadata; review the Security Audits panel on this Prism page before adding any skill from an external repo to your agent.
SKILL.md
READMESKILL.md - Golang Code Style
[ { "id": 1, "name": "zero-value-intent-signal", "description": "var vs := signals intent: var for zero-value start, := for non-zero — even when the zero value IS the business default", "prompt": "Write a Go file `session.go` in package `session`. Create a Session struct with fields: userID string, requestCount int, isAuthenticated bool, lastError error, startedAt time.Time, tags []string. Add a constructor NewSession(userID string) that initializes the struct. In the constructor, requestCount starts at zero (it will be incremented on each use), isAuthenticated starts false (it must be explicitly set after login), lastError starts nil, startedAt is set to time.Now(), and tags is initialized as an empty slice. Also add a local variable inside a method Describe() that builds a description string from a fixed prefix 'session:'.", "trap": "Model uses := for all fields including zero-value ones (requestCount := 0, isAuthenticated := false) or uses var for non-zero assignments like startedAt, obscuring intent", "assertions": [ { "id": "1.1", "text": "requestCount is NOT explicitly initialized to 0 in the constructor — the zero value is relied upon via var or struct literal without that field, not via requestCount := 0" }, { "id": "1.2", "text": "startedAt uses := assignment (startedAt := time.Now() or field assignment) — NOT var startedAt time.Time followed by assignment — because it has a non-zero meaningful value" }, { "id": "1.3", "text": "The fixed prefix string variable in Describe() uses := (prefix := 'session:') — not var prefix string = 'session:'" }, { "id": "1.4", "text": "tags is initialized with []string{} or make([]string, 0) — never nil — because nil slices serialize to null in JSON" } ] }, { "id": 2, "name": "empty-slice-map-not-nil", "description": "Empty collections initialized as []T{} or make(), never nil", "prompt": "Write a Go file `handler.go` in package `api`. Create a Handler struct. Add a method ListUsers that returns a slice of User structs (define User with Name and Email fields). Add a method GetTags that returns a map[string]string. Both methods should return empty collections when there's no data. Add a method BuildResponse that takes a slice of results and a map of metadata and processes them.", "trap": "Model returns nil slices/maps or uses uninitialized var declarations for empty collections, causing nil != empty issues in JSON serialization and caller code", "assertions": [ { "id": "2.1", "text": "Empty slice return uses []User{} or make([]User, 0) — never returns nil or an uninitialized var declaration without assignment" }, { "id": "2.2", "text": "Empty map return uses map[string]string{} or make(map[string]string) — never returns nil or an uninitialized var declaration without assignment" }, { "id": "2.3", "text": "When capacity is known (e.g., from len(input)), make() with capacity hint is used for preallocating slices or maps" } ] }, { "id": 3, "name": "named-struct-fields-nested", "description": "All struct literals use named fields, including nested and anonymous structs", "prompt": "Write a Go file `middleware.go` in package `middleware`. Create a RateLimiter struct with fields: windowSize time.Duration, maxRequests int, perIP bool. Create a middleware chain config using a struct literal with nested structs: a TimeoutConfig containing duration and errorMessage, a RetryConfig containing maxAttempts int and backoff time.Duration, and a CircuitBreakerConfig containing threshold float64 and resetAfter time.Duration. Instantiate each of these structs as part of a larger MiddlewareConfig struct. Also create a tls.Config with MinVersion and a list of cipher suites.", "trap": "Model uses positional struct literals for the