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 Api Design

ASecurity

Enforces Go package and API design — small exported surfaces, packages named for what they provide, functional options instead of growing constructors, context first, no init side effects, and changes that stay backward compatible. Use when creating or restructuring Go packages, designing an exported API or library, or reviewing a public interface, and when the user mentions package layout, internal/, functional options, breaking changes, semantic import versioning, or asks "how should I stru...

2 stars
0 votes
0 copies
1 views
Added 9/19/2026
developmentgoapidatabase

Works with

cliapi

Security Analysis

A100/100

Scanned 9/19/2026

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

Installs into .claude/skills of the current project.

Are you the author of Go Api Design?

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

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

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-api-design
description: Enforces Go package and API design — small exported surfaces, packages named for what they provide, functional options instead of growing constructors, context first, no init side effects, and changes that stay backward compatible. Use when creating or restructuring Go packages, designing an exported API or library, or reviewing a public interface, and when the user mentions package layout, internal/, functional options, breaking changes, semantic import versioning, or asks "how should I structure this package", "is this a good API".
---

# Go API design

The exported surface is a promise. Everything unexported can change freely; everything exported cannot.

## Name packages for what they provide

A package name is a prefix on every identifier a caller reads, so it should say something.

```
Good:  store, retry, httpclient, tokens
Bad:   util, common, helpers, base, misc, models
```

`util` attracts unrelated code forever and tells a reader nothing at the call site. When you cannot name a package precisely, the contents do not belong together yet — put them where they are used and split later once a real seam appears.

Short, lowercase, one word, no underscores, no plurals. Organise by capability, not by layer: a `handlers` package holding forty unrelated HTTP handlers is a folder, not a package.

## Export as little as possible

Start every type, function, field, and constant lowercase. Export when a caller outside the package needs it, and not before — unexporting later is a breaking change, exporting later is free.

`internal/` enforces this at the compiler level: anything under `internal/` is importable only by code rooted at its parent, so you can share code across your own packages without it becoming public API.

## Constructors: options over parameters

A constructor that keeps growing parameters breaks every caller each time.

```go
// Breaks on every addition
func New(addr string, timeout time.Duration, retries int, tls *tls.Config) *Client
```

Functional options add configuration without breaking anyone, and keep the common call short:

```go
type Option func(*Client)

func WithTimeout(d time.Duration) Option { return func(c *Client) { c.timeout = d } }
func WithRetries(n int) Option           { return func(c *Client) { c.retries = n } }

func New(addr string, opts ...Option) *Client {
    c := &Client{addr: addr, timeout: 30 * time.Second, retries: 3}
    for _, opt := range opts {
        opt(c)
    }
    return c
}

client := New("api.example.com")                       // sane defaults
client := New("api.example.com", WithTimeout(5*time.Second))
```

Required arguments stay positional; optional ones become options. For two or three settings that will not grow, an exported config struct is simpler and honest — do not reach for options reflexively.

## Context first, error last

```go
func (s *Store) Get(ctx context.Context, id string) (*Order, error)
```

Anything doing I/O, blocking, or spawning work takes `ctx` as its first parameter, even if today's implementation ignores it — adding it later breaks every caller. Never put a `context.Context` in a struct field.

## Take the narrowest input

Accept `io.Reader` over `*os.File`, an interface over a struct, a slice over a channel where either works. Return concrete types so callers keep access to everything the type offers.

## No package-level side effects

`init()` that dials a database, reads a file, or registers global state makes the package impossible to test and its import order significant. Do the work in an exported constructor the caller controls. Package-level mutable variables are shared state with no owner — the exception is a documented sentinel error or a genuinely immutable table.

Avoid a package-level default instance that callers mutate. Let the caller construct what it needs and pass it down.

## Design errors as part of the API

Callers branch on failures, so failures are API. Decide deliberately which conditions are inspectable, export those sentinels or types, and document them on the function that returns them. Everything else stays an opaque wrapped error you are free to reword.

## Compatibility

Within a major version these break callers, and are therefore off limits: renaming or removing anything exported, adding a parameter, changing a return type, adding a method to an interface others implement, changing a struct another package constructs with positional literals.

These are safe: adding a new function or type, adding a field to a struct callers build with field names, adding a method to a concrete type.

Breaking on purpose means `/v2` in the module path — semantic import versioning lets both versions coexist in one build, which is what makes migration possible at all.

## Document the exported surface

A doc comment on every exported identifier, starting with its name. A `doc.go` for the package overview when it needs more than a sentence. Runnable `Example` functions in the test file — they appear in the docs and fail the build when they drift from reality. If the doc comment is hard to write, the API is hard to use; fix the API.

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 →