idiomatic-go
Skill4 starsChanged 9 months agoMITView on GitHub
Write clean, idiomatic Go following community conventions and effective patterns. Use when the user writes Go code, designs packages, defines interfaces, uses struct embedding, writes receiver methods, organizes Go projects, or asks about Go best practices and conventions.
In this repository78 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rules/agents.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/claude-initial-setup.mdcCursor rule
- parallel-task-executionSkill
- subagent-patternsSkill
- task-coordinationSkill
- agent-communicationSkill
- context-managementSkill
- multi-agent-orchestrationSkill
- deploy-strategiesSkill
- github-actions-guideSkill
- pipeline-patternsSkill
- anthropic-sdk-guideSkill
- prompt-engineeringSkill
- tool-use-patternsSkill
- automated-review-setupSkill
- pr-standardsSkill
- review-checklistSkill
- file-organizationSkill
- immutability-patternsSkill
- naming-conventionsSkill
- branching-strategySkill
- commit-conventionsSkill
- pr-workflowSkill
- migration-patternsSkill
- query-optimizationSkill
- schema-design-guideSkill
- error-tracingSkill
- log-analysisSkill
- systematic-debuggingSkill
- django-admin-customizationSkill
- django-orm-masterySkill
- drf-api-patternsSkill
- docker-compose-guideSkill
- dockerfile-best-practicesSkill
- multi-stage-buildsSkill
- express-error-handlingSkill
- middleware-patternsSkill
- rest-api-nodeSkill
- async-fastapiSkill
- dependency-injection-fastapiSkill
- pydantic-validationSkill
- concurrency-patterns-goSkill
- error-handling-goSkill
- automation-triggersSkill
- hook-recipesSkill
- pre-post-hooksSkill
- junit-testingSkill
- maven-gradle-guideSkill
- spring-boot-patternsSkill
- mcp-resource-patternsSkill
- mcp-server-creationSkill
- mcp-tool-designSkill
- context-optimizationSkill
- knowledge-persistenceSkill
- memory-patternsSkill
- caching-strategiesSkill
- lazy-loading-patternsSkill
- profiling-guideSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 5 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Write Go code that follows community conventions, leveraging interfaces, struct embedding, and proper package organization for clean, …
- Distinctive: line 85
Use pointer receivers when the method mutates state or the struct is large.
- Distinctive: line 86
Use value receivers for small, immutable types.
- Distinctive: line 124
Follow the standard Go project layout conventions.
- Very specific: line 150
Avoid package util or package common -- name packages by what they provide.
- Very specific: line 151
Use internal/ to prevent external imports of implementation details.
- Distinctive: line 156
Use the functional options pattern for configurable constructors with clean defaults.
- Very specific: line 209
Only use Get prefix when it disambiguates (e.g., HTTP handlers).
- Very specific: line 212
Use explicit initialization in main() or constructors.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Idiomatic Go
Write Go code that follows community conventions, leveraging interfaces, struct embedding, and proper package organization for clean, maintainable projects.
When to Use
- Starting a new Go project or package
- Designing interfaces and struct hierarchies
- Choosing between value and pointer receivers
- Organizing packages and project layout
- Reviewing Go code for idiom violations
Core Patterns
Pattern 1: Interface Design
Define small interfaces at the point of consumption, not at the implementation site. The Go proverb: "The bigger the interface, the weaker the abstraction."
// GOOD: small, focused interfaces defined by the consumer
package storage
// Reader is defined where it is used, not where it is implemented.
type Reader interface {
Read(ctx context.Context, key string) ([]byte, error)
}
func NewCache(reader Reader, ttl time.Duration) *Cache {
return &Cache{reader: reader, ttl: ttl}
}
// Accept interfaces, return structs
func ProcessData(r io.Reader) (*Result, error) {
data, err := io.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("reading data: %w", err)
}
return &Result{Data: data}, nil
}Pattern 2: Struct Embedding
Embed types to compose behavior without inheritance. Embedding promotes the embedded type's methods to the outer struct.
type Logger struct {
prefix string
}
func (l *Logger) Log(msg string) {
fmt.Printf("[%s] %s\n", l.prefix, msg)
}
type Server struct {
Logger // embed Logger -- Server now has a Log method
addr string
}
func NewServer(addr string) *Server {
return &Server{
Logger: Logger{prefix: "server"},
addr: addr,
}
}
// Usage
s := NewServer(":8080")
s.Log("starting") // promoted from LoggerPattern 3: Receiver Methods -- Value vs Pointer
Use pointer receivers when the method mutates state or the struct is large. Use value receivers for small, immutable types.
// Value receiver: small, immutable, safe to copy
type Point struct {
X, Y float64
}
func (p Point) Distance(other Point) float64 {
dx := p.X - other.X
dy := p.Y - other.Y
return math.Sqrt(dx*dx + dy*dy)
}
// Pointer receiver: mutates state
type Counter struct {
mu sync.Mutex
count int64
}
func (c *Counter) Increment() {
c.mu.Lock()
defer c.mu.Unlock()
c.count++
}
func (c *Counter) Value() int64 {
c.mu.Lock()
defer c.mu.Unlock()
return c.count
}Rule: if any method on a type needs a pointer receiver, make all methods use pointer receivers for consistency.
Pattern 4: Package Organization
Follow the standard Go project layout conventions.
myapp/
cmd/
server/
main.go // entrypoint: flag parsing, wiring, server start
worker/
main.go
internal/ // private packages, not importable by other modules
user/
user.go // domain types
service.go // business logic
repository.go // data access interface
postgres.go // repository implementation
order/
order.go
pkg/ // public library code (optional, use sparingly)
httputil/
middleware.go
go.mod
go.sumGuidelines:
- Package names are short, lowercase, single-word (no underscores or mixedCase).
- Avoid
package utilorpackage common-- name packages by what they provide. - Use
internal/to prevent external imports of implementation details. - One package per concept, not per file type.
Pattern 5: Functional Options
Use the functional options pattern for configurable constructors with clean defaults.
type Server struct {
addr string
readTimeout time.Duration
writeTimeout time.Duration
logger *slog.Logger
}
type Option func(*Server)
func WithReadTimeout(d time.Duration) Option {
return func(s *Server) { s.readTimeout = d }
}
func WithWriteTimeout(d time.Duration) Option {
return func(s *Server) { s.writeTimeout = d }
}
func WithLogger(l *slog.Logger) Option {
return func(s *Server) { s.logger = l }
}
func NewServer(addr string, opts ...Option) *Server {
s := &Server{
addr: addr,
readTimeout: 5 * time.Second,
writeTimeout: 10 * time.Second,
logger: slog.Default(),
}
for _, opt := range opts {
opt(s)
}
return s
}
// Usage
srv := NewServer(":8080",
WithReadTimeout(10*time.Second),
WithLogger(customLogger),
)Anti-Patterns
- Large interfaces defined at the implementation -- Define interfaces where they are consumed. A 10-method interface is almost never needed.
package utils-- This is a code smell in Go. Move functions to the package that uses them or name the package by its domain.- Getter prefixes -- Go convention is
user.Name(), notuser.GetName(). Only useGetprefix when it disambiguates (e.g., HTTP handlers). - init() for complex logic --
init()runs implicitly and makes testing hard. Use explicit initialization inmain()or constructors.// BAD var db *sql.DB func init() { db, _ = sql.Open("postgres", os.Getenv("DB_URL")) } // GOOD func NewDB(url string) (*sql.DB, error) { return sql.Open("postgres", url) } - Naked returns in long functions -- Named returns are fine for documentation,
but naked
returnin functions longer than a few lines hurts readability.
Quick Reference
| Principle | Guideline |
| Interfaces | Small, consumer-defined, accept interfaces |
| Returns | Return concrete structs, not interfaces |
| Receivers | Pointer if mutating or large; value if small and immutable |
| Packages | Short names, by domain, use internal/ |
| Constructors | NewXxx functions, functional options for config |
| Errors | Return error as last value, wrap with %w |
| Naming | MixedCaps, no underscores, short locals |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

