Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Go Interfaces

ASecurity

Enforces Go interface design — interfaces defined by the consumer, kept to one or two methods, accepted as parameters while structs are returned, and never created before a second implementation exists. Use when writing or reviewing Go abstractions, mocks, or package boundaries, and when the user mentions interface design, mocking, dependency injection, "accept interfaces return structs", io.Reader, io.Writer, generics vs interfaces, or asks "should this be an interface", "how do I test this ...

2 stars
0 votes
0 copies
2 views
Added 9/19/2026
developmentgosqltesting

Security Analysis

A100/100

Scanned 9/19/2026

$npx -y skills add CasLubbers/code-design-skills --skill go-interfaces --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Go Interfaces?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Go Interfaces
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/caslubbers-go-interfaces/badge)](https://www.skillsdirectory.com/skills/caslubbers-go-interfaces)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: go-interfaces
description: Enforces Go interface design — interfaces defined by the consumer, kept to one or two methods, accepted as parameters while structs are returned, and never created before a second implementation exists. Use when writing or reviewing Go abstractions, mocks, or package boundaries, and when the user mentions interface design, mocking, dependency injection, "accept interfaces return structs", io.Reader, io.Writer, generics vs interfaces, or asks "should this be an interface", "how do I test this dependency".
---

# Go interfaces

Go interfaces are satisfied implicitly. The implementing type never names the interface, which flips where the interface belongs.

## The consumer declares the interface

Define it in the package that *uses* it, listing only what that package calls.

```go
// package notify — the consumer. It needs exactly one method.
type UserFinder interface {
    FindUser(ctx context.Context, id string) (*User, error)
}

func Send(ctx context.Context, f UserFinder, id string) error { ... }
```

```go
// package store — the producer. Returns a concrete type, declares no interface.
func New(db *sql.DB) *Store { ... }
func (s *Store) FindUser(ctx context.Context, id string) (*User, error) { ... }
```

`*store.Store` satisfies `notify.UserFinder` with no import between them and no declaration linking them. Producer-side interfaces (`store.StoreInterface` next to `store.Store`) invert this: they force every consumer to depend on a surface far wider than it uses, and they change whenever any consumer needs something new.

## Keep them small

One or two methods. The standard library's most reused interfaces have one:

```go
type Reader interface { Read(p []byte) (n int, err error) }
type Writer interface { Write(p []byte) (n int, err error) }
type Stringer interface { String() string }
```

A large interface is not reusable, not implementable in a test without a pile of stubs, and usually a struct wearing a disguise. If yours has seven methods, you have described a type, not a capability.

## Accept interfaces, return structs

```go
// Good — flexible in, concrete out
func NewProcessor(r io.Reader) *Processor
func (p *Processor) Result() *Report
```

Returning an interface hides the concrete type's other methods and fields from callers for no gain, and makes the returned value harder to extend without breaking the interface. Return the struct; let the caller narrow it.

## Reuse the standard interfaces

Before defining anything, check whether `io.Reader`, `io.Writer`, `io.Closer`, `fmt.Stringer`, `error`, `sort.Interface`, or `context.Context` already says it. A function taking `io.Reader` works with files, network connections, `strings.Reader`, `bytes.Buffer`, and gzip streams for free. One taking `*os.File` works with files.

## Wait for the second implementation

An interface with one implementor and no test double is indirection with no seam. Write the concrete type, use it, and extract the interface when the second caller or the first test genuinely needs it — extraction is a two-minute refactor, and by then you know which methods belong.

The exception that earns its keep early: a boundary you cannot run in a test (network, clock, filesystem, payment provider). There, the test double *is* the second implementation.

## Testing without a mocking framework

A hand-written fake is usually shorter than the generated mock and reads better in the failure.

```go
type fakeFinder struct {
    user *User
    err  error
}

func (f fakeFinder) FindUser(context.Context, string) (*User, error) {
    return f.user, f.err
}
```

For a one-method interface, a function type removes even that:

```go
type FinderFunc func(context.Context, string) (*User, error)

func (f FinderFunc) FindUser(ctx context.Context, id string) (*User, error) {
    return f(ctx, id)
}
```

This is how `http.HandlerFunc` works.

## Naming

Single-method interfaces take the method name plus `-er`: `Reader`, `Formatter`, `UserFinder`. No `I` prefix, no `Impl` suffix on the implementation. The concrete type gets the plain noun (`Store`), the interface gets the capability (`UserFinder`).

## Assert satisfaction at compile time

When a type must satisfy an interface it does not mention, state it once so the failure lands at build time with a clear message:

```go
var _ http.Handler = (*Router)(nil)
```

## Empty interfaces and generics

`any` discards all type information and pushes the failure to runtime. If the function is genuinely type-independent, use a type parameter instead:

```go
// Good
func Keys[K comparable, V any](m map[K]V) []K

// Bad — caller must type-assert, compiler cannot help
func Keys(m any) []any
```

Reach for generics when the alternative is the same function copy-pasted per type. Do not parameterise a function that has exactly one instantiation.

Attribution

CasLubbersCasLubbers
View sourceSee grades on GitHubMore from CasLubbers →
SSkills DirectorySkills Directory

Your tool, in front of Claude Code builders.

3 founder slots · $299/mo · GSC-verified traffic · sponsors can never buy grades.

See placements

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Your tool, in front of Claude Code builders.

3 founder slots · $299/mo · GSC-verified traffic · sponsors can never buy grades.

See placements

Related Skills

Clean Code

Pragmatic coding standards - concise, direct, no over-engineering, no unnecessary comments

304955 votes

Browser Extension Developer

Use this skill when developing or maintaining browser extension code in the `browser/` directory, including Chrome/Firefox/Edge compatibility, content scripts, background scripts, or i18n updates.

285172 votes

Seo Optimizer

SEO optimization with keyword analysis, readability assessment, technical validation, content quality. Use for search rankings, blog posts, content audits, or encountering keyword density, readability scores, meta tags, schema markup errors.

2222 votes

Google Official Seo Guide

Official Google SEO guide covering search optimization, best practices, Search Console, crawling, indexing, and improving website search visibility based on official Google documentation

1862 votes

Tanstack Start

Build a full-stack TanStack Start app on Cloudflare Workers from scratch — SSR, file-based routing, server functions, D1+Drizzle, better-auth, Tailwind v4+shadcn/ui. Use whenever the user mentions TanStack Start, asks to scaffold a full-stack Cloudflare app with SSR, wants an SSR dashboard, or asks for a React 19 + Cloudflare Workers app with file-based routing and server functions — even if they don't name TanStack Start specifically. No template repo — Claude generates every file fresh per ...

10341 votes
View all in development →