golang-patterns
OfficialPatrones idiomáticos de Go, buenas prácticas y convenciones para construir aplicaciones Go robustas, eficientes y mantenibles.
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: Patrones idiomáticos de Go, buenas prácticas y convenciones para construir aplicaciones Go robustas, eficientes y mantenibles.
origin: ECC
---
# Patrones de Desarrollo Go
Patrones idiomáticos de Go y buenas prácticas para construir aplicaciones robustas, eficientes y mantenibles.
## Cuándo Activar
- Escribir nuevo código Go
- Revisar código Go
- Refactorizar código Go existente
- Diseñar paquetes/módulos Go
## Principios Fundamentales
### 1. Simplicidad y Claridad
Go favorece la simplicidad sobre la astucia. El código debe ser obvio y fácil de leer.
```go
// Bien: Claro y directo
func GetUser(id string) (*User, error) {
user, err := db.FindUser(id)
if err != nil {
return nil, fmt.Errorf("get user %s: %w", id, err)
}
return user, nil
}
// Mal: Demasiado ingenioso
func GetUser(id string) (*User, error) {
return func() (*User, error) {
if u, e := db.FindUser(id); e == nil {
return u, nil
} else {
return nil, e
}
}()
}
```
### 2. Hacer que el Valor Cero Sea Útil
Diseñar tipos para que su valor cero sea inmediatamente usable sin inicialización.
```go
// Bien: El valor cero es útil
type Counter struct {
mu sync.Mutex
count int // el valor cero es 0, listo para usar
}
func (c *Counter) Inc() {
c.mu.Lock()
c.count++
c.mu.Unlock()
}
// Bien: bytes.Buffer funciona con el valor cero
var buf bytes.Buffer
buf.WriteString("hello")
// Mal: Requiere inicialización
type BadCounter struct {
counts map[string]int // el mapa nil causará panic
}
```
### 3. Aceptar Interfaces, Retornar Structs
Las funciones deben aceptar parámetros de interfaz y retornar tipos concretos.
```go
// Bien: Acepta interfaz, retorna tipo concreto
func ProcessData(r io.Reader) (*Result, error) {
data, err := io.ReadAll(r)
if err != nil {
return nil, err
}
return &Result{Data: data}, nil
}
// Mal: Retorna interfaz (oculta detaUse 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-599b2f12-3d34-4271-9f50-95b3abfe3184",
"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.