Xpersona
G

golang-structs-interfaces

CLAWHUB · Unverified

Golang struct and interface design patterns — composition, embedding, type assertions, type switches, interface segregation, dependency injection via interfaces, struct field tags, and pointer vs value receivers. Use this skill when designing Go types, defining or implementing interfaces, embedding structs or interfaces, writing type assertions or type switches, adding struct field tags for JSON/YAML/DB serialization, or choosing between pointer and value receivers. Also use when the user asks about "accept interfaces, return structs", compile-time interface checks, or composing small interfaces into larger ones.

62
Rank
84
Safety
1.2k
Downloads

About

What it does, and when to use it.

Capability contract not published. No trust telemetry is available yet. 1.2K downloads reported by the source. Last updated 10/11/2026.

Avoid when

  • Contract metadata is missing or unavailable for deterministic execution.

Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing

Install and run

Setup complexity: low.

clawhub skill install s173arkhs3131fq5jf769qq75583hdgt:golang-structs-interfaces
  1. Install using `clawhub skill install s173arkhs3131fq5jf769qq75583hdgt:golang-structs-interfaces` in an isolated environment before connecting it to live workloads.
  2. No published capability contract is available yet, so validate auth and request/response behavior manually.
  3. Review the upstream CLAWHUB listing at https://clawhub.ai/samber/golang-structs-interfaces before using production credentials.

Contract: missing

curl -s "https://www.xpersona.co/api/v1/agents/clawhub-samber-golang-structs-interfaces/snapshot"

Run-check

$0.02 USD

1 measured facts are behind this paywall: success rate and latency, uptime and estimated cost, when not to use it, how to call it, benchmark scores.

Agents pay $0.02 in USDC. A card payment is $0.50, the smallest a card allows.

Documentation

CLAWHUB

99,591 characters of source documentation, loaded on request.

Extracted files

4 files captured from the source.

SKILL.md

---
name: golang-structs-interfaces
description: 'Golang struct and interface design patterns — composition, embedding, type assertions, type switches, interface segregation, dependency injection via interfaces, struct field tags, and pointer vs value receivers. Use this skill when designing Go types, defining or implementing interfaces, embedding structs or interfaces, writing type assertions or type switches, adding struct field tags for JSON/YAML/DB serialization, or choosing between pointer and value receivers. Also use when the user asks about "accept interfaces, return structs", compile-time interface checks, or composing small interfaces into larger ones.'
user-invocable: true
license: MIT
compatibility: Designed for Claude Code, Codex or similar harness, and for projects using Golang.
metadata:
  author: samber
  version: "1.2.0"
  openclaw:
    emoji: "🧩"
    homepage: https://github.com/samber/cc-skills-golang
    requires:
      bins:
        - go
    install: []
allowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent AskUserQuestion
paths:
  - "**/*.go"
---

**Persona:** You are a Go type system designer. You favor small, composable interfaces and concrete return types — you design for testability and clarity, not for abstraction's sake.

> **Community default.** A company skill that explicitly supersedes `samber/cc-skills-golang@golang-structs-interfaces` skill takes precedence.

# Go Structs & Interfaces

## Interface Design Principles

### Keep Interfaces Small

> "The bigger the interface, the weaker the abstraction." — Go Proverbs

Interfaces SHOULD have 1-3 methods. Small interfaces are easier to implement, mock, and compose. If you need a larger contract, compose it from small interfaces:

→ See `samber/cc-skills-golang@golang-naming` skill for interface naming conventions (method + "-er" suffix, canonical names)

```go
type Reader interface {
    Read(p []byte) (n int, err error)
}

type Writer interface {
    Write(p []byte) (n int, err error)
}

// Composed from small interfaces
type ReadWriter interface {
    Reader
    Writer
}
```

Compose larger interfaces from smaller ones:

```go
type ReadWriteCloser interface {
    io.Reader
    io.Writer
    io.Closer
}
```

### Define Interfaces Where They're Consumed

Interfaces Belong to Consumers.

Interfaces MUST be defined where consumed, not where implemented. This keeps the consumer in control of the contract and avoids importing a package just for its interface.

```go
// package notification — defines only what it needs
type Sender interface {
    Send(to, body string) error
}

type Service struct {
    sender Sender
}
```

The `email` package exports a concrete `Client` struct — it doesn't need to know about `Sender`.

### Accept Interfaces, Return Structs

Functions SHOULD accept interface parameters for flexibility and return concrete types for clarity. Callers get full access to the returned type's fields and methods; consumers upstr

_meta.json

{
  "ownerId": "kn72rhnkwjfeex9wr1n7y24qa983cjn3",
  "slug": "golang-structs-interfaces",
  "version": "1.2.0",
  "publishedAt": 1787463270891
}

skill-card.md

## Description:

Golang struct and interface design patterns - composition, embedding, type assertions, type switches, interface segregation, dependency injection via interfaces, struct field tags, and pointer vs value receivers.

This skill is ready for commercial/non-commercial use.

## Publisher:

[samber](https://clawhub.ai/user/samber)

### License/Terms of Use:

MIT-0

## Use Case:

Developers and engineers use this skill to design Go structs and interfaces, choose receiver styles, apply composition and embedding, and handle type assertions, field tags, generics, dependency injection, and compile-time interface checks.

### Deployment Geography for Use:

Global

## Known Risks and Mitigations:

Risk: The skill can propose edits to Go source files.

Mitigation: Review proposed diffs before accepting them, especially changes to public interfaces, receiver types, serialization tags, and dependency boundaries.

Risk: The skill can suggest or run Go, golangci-lint, and git commands in compatible coding harnesses.

Mitigation: Review command intent and scope before execution, and avoid approving git operations that stage, commit, or rewrite unrelated work.

## Reference(s):

- [ClawHub skill page](https://clawhub.ai/samber/skills/golang-structs-interfaces)
- [Publisher profile](https://clawhub.ai/user/samber)
- [Project homepage](https://github.com/samber/cc-skills-golang)
- [Go sync noCopy reference](https://pkg.go.dev/sync#noCopy)

## Skill Output:

**Output Type(s):** [text, markdown, code, shell commands, configuration, guidance]

**Output Format:** [Markdown guidance with Go code examples and optional shell commands]

**Output Parameters:** [1D]

**Other Properties Related to Output:** [May propose Go file edits and Go tooling commands when used in a coding harness.]

## Skill Version(s):

1.2.0 (source: server evidence and frontmatter)

## Ethical Considerations:

Users should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment.

evals/evals.json

[
  {
    "id": 1,
    "name": "interface-at-consumer-not-implementor",
    "description": "Tests whether the model defines interfaces where they are consumed, not where they are implemented",
    "prompt": "I'm writing a Go notification service that can send emails. I have an email package with a Client struct that has a Send method. I also have a notification package that needs to use this email client. Where should I define the interface?",
    "trap": "Without the skill, the model often puts the interface in the email package (the implementor). The skill says interfaces MUST be defined where consumed, not where implemented.",
    "assertions": [
      {"id": "1.1", "text": "Interface is defined in the notification package (the consumer), NOT in the email package"},
      {"id": "1.2", "text": "Interface has only the methods the notification package needs (not the full email.Client API)"},
      {"id": "1.3", "text": "Email package exports a concrete Client struct, not an interface"},
      {"id": "1.4", "text": "Explains WHY: keeps the consumer in control of the contract, avoids importing a package just for its interface"},
      {"id": "1.5", "text": "Notification service depends on its own interface, not on email package types"}
    ]
  },
  {
    "id": 2,
    "name": "return-structs-not-interfaces",
    "description": "Tests whether the model returns concrete types from constructors, not interfaces",
    "prompt": "I'm designing a Go package with a UserService that depends on a UserStore interface. Should my NewUserService constructor return *UserService or UserServiceInterface? Show me the constructor signature.",
    "trap": "Without the skill, the model may suggest returning an interface for 'flexibility' or 'abstraction'. The skill says functions SHOULD return concrete types -- NEVER return interfaces from constructors.",
    "assertions": [
      {"id": "2.1", "text": "Constructor returns *UserService (concrete type), NOT an interface"},
      {"id": "2.2", "text": "Constructor accepts UserStore as an interface parameter (accept interfaces)"},
      {"id": "2.3", "text": "Explains WHY: callers get full access to the concrete type's fields/methods; consumers can assign to interface if needed"},
      {"id": "2.4", "text": "Explicitly states that returning interfaces from constructors is bad practice"},
      {"id": "2.5", "text": "The accept-interfaces-return-structs principle is stated or demonstrated"}
    ]
  },
  {
    "id": 3,
    "name": "premature-interface-trap",
    "description": "Tests whether the model avoids creating interfaces prematurely when there is only one implementation",
    "prompt": "I'm writing a Go application with a UserRepository that talks to PostgreSQL. It's the only database we'll ever use. Should I create a UserRepository interface and a concrete postgresUserRepository struct, or just use a concrete struct directly?",
    "trap": "Without the skill, the model almost always suggests creating an interface '

Sponsored

Ads related to golang-structs-interfaces and adjacent AI workflows.