golang-patterns
Official>
What this skill does
When applied, it prepends a system prompt before your request is sent — no extra calls and no change to how you are billed beyond the added tokens.
---
name: golang-patterns
description: >
Go-specific design patterns and best practices including functional options,
small interfaces, dependency injection, concurrency patterns, error handling,
and package organization. Use when working with Go code to apply idiomatic
Go patterns.
metadata:
origin: ECC
globs: ["**/*.go", "**/go.mod", "**/go.sum"]
---
# Go Patterns
> This skill provides comprehensive Go patterns extending common design principles with Go-specific idioms.
## Functional Options
Use the functional options pattern for flexible constructor configuration:
```go
type Option func(*Server)
func WithPort(port int) Option {
return func(s *Server) { s.port = port }
}
func NewServer(opts ...Option) *Server {
s := &Server{port: 8080}
for _, opt := range opts {
opt(s)
}
return s
}
```
**Benefits:**
- Backward compatible API evolution
- Optional parameters with defaults
- Self-documenting configuration
## Small Interfaces
Define interfaces where they are used, not where they are implemented.
**Principle:** Accept interfaces, return structs
```go
// Good: Small, focused interface defined at point of use
type UserStore interface {
GetUser(id string) (*User, error)
}
func ProcessUser(store UserStore, id string) error {
user, err := store.GetUser(id)
// ...
}
```
**Benefits:**
- Easier testing and mocking
- Loose coupling
- Clear dependencies
## Dependency Injection
Use constructor functions to inject dependencies:
```go
func NewUserService(repo UserRepository, logger Logger) *UserService {
return &UserService{
repo: repo,
logger: logger,
}
}
```
**Pattern:**
- Constructor functions (New* prefix)
- Explicit dependencies as parameters
- Return concrete types
- Validate dependencies in constructor
## Concurrency Patterns
### Worker Pool
```go
func workerPool(jobs <-chan Job, results chan<- Result, workers int) {
var wg sync.WaitGroup
for i := 0; i < workers; i++ {
Use this skill
Add a "skill" field with the skill’s ID to your chat completion request. It is applied server-side before your prompt is sent — no extra calls.
{
"model": "gpt-4o-mini",
"skill": "imp-08c09c94-9bc9-47e5-ab90-41409323da5c",
"messages": [{ "role": "user", "content": "…" }]
}Install the skill, enable it in your dashboard and (optionally) limit it to specific models. It then applies automatically to every matching request — with no "skill" field to send each time.
Set it up in your dashboardMore skills
Set up and use 1Password CLI for sign-in, desktop integration, and reading or injecting secrets.
Create, view, edit, delete, search, move, or export Apple Notes via the memo CLI on macOS.
List, add, edit, complete, or delete Apple Reminders and reminder lists via remindctl.
Create, search, and manage Bear notes via grizzly CLI.
Monitor blogs and RSS/Atom feeds for updates using the blogwatcher CLI.
BluOS CLI (blu) for discovery, playback, grouping, and volume.
Capture frames or clips from RTSP/ONVIF cameras.
Search, install, update, sync, or publish agent skills with the ClawHub CLI and registry.