← ClaudeAtlas

go-typeslisted

Go type system advisor. Always use this skill when designing Go interfaces, working with structs and embedding, using generics, performing type assertions or type switches, defining custom error types, choosing between named types and aliases, or thinking about zero values. Use when the user says "how do I type this in Go", "when should I use an interface", "should I embed or compose", "how do I write a generic function", "how do I assert a type", "how do I wrap an error", "named type vs type alias", or "is my interface too big". Read this skill before answering any Go type system question.
AllThingsSmitty/agent-skills · ★ 1 · Code & Development · score 74
Install: claude install-skill AllThingsSmitty/agent-skills
# Go Types Go's type system rewards restraint. The most common mistakes — large interfaces, premature generics, type assertions without comma-ok — all come from over-engineering. Prefer concrete types until abstraction earns its place. ## Interfaces Interfaces are satisfied implicitly. No `implements` keyword — if a type has the methods, it satisfies the interface. This makes interfaces powerful and dangerous: it's easy to define one that nobody actually satisfies. **Keep interfaces small.** The standard library's best interfaces have one or two methods: `io.Reader`, `io.Writer`, `fmt.Stringer`. One method = one behavior = easy to satisfy, easy to compose. ```go // Good: focused, composable type Reader interface { Read(p []byte) (n int, err error) } // Bad: eight methods means eight things your mock, stub, or test double must implement type UserService interface { GetUser(id string) (*User, error) ListUsers() ([]*User, error) CreateUser(u *User) error UpdateUser(u *User) error DeleteUser(id string) error SearchUsers(query string) ([]*User, error) GetUserByEmail(email string) (*User, error) CountUsers() (int, error) } ``` **Define interfaces at the point of use, not the point of definition.** The package that *uses* an abstraction should own the interface. The package that *implements* it should expose a concrete type. This avoids unnecessary coupling and import cycles. ```go // Bad: defined in the implementing package — forces calle