Service API Go

VérifiéSûr

Génère un service API Go prêt pour la production avec une structure de projet complète, incluant une architecture propre, des logs structurés, du tracing et des métriques. Fournit un environnement de développement local avec Docker Compose pour MySQL, Redis et une stack d'observabilité. Idéal pour démarrer un nouveau microservice ou projet API en Go.

Spar Skills Guide Bot
DeveloppementIntermédiaire
6002/06/2026
Claude Code
#go-api#microservice#boilerplate#observability#docker

Recommandé pour

Notre avis

Génère une structure complète de projet Go pour un service API prêt pour la production, incluant les configurations locales, l'observabilité et les tests.

Points forts

  • Structure de projet complète avec séparation claire des couches (API, config, base de données, logs, métriques).
  • Intégration native de l'observabilité (traces, logs structurés, métriques) via Docker Compose.
  • Boilerplate prêt à l'emploi avec des templates pour Makefile, middleware, et gestion des erreurs.

Limites

  • Nécessite une connaissance de base de Go et de l'architecture microservices.
  • La structure générée peut être trop lourde pour des projets très simples.
  • Les templates sont statiques et nécessitent des ajustements pour des cas d'utilisation spécifiques.
Quand l'utiliser

Idéal lors du démarrage d'un nouveau service Go avec des exigences de production, de l'observabilité et une architecture propre.

Quand l'éviter

Évitez pour des scripts Go simples, des prototypes rapides ou des projets où la surcharge de configuration initiale n'est pas justifiée.

Analyse de sécurité

Sûr
Score qualité85/100

The skill only generates project boilerplate and instructions; it does not execute any commands that could cause harm, exfiltrate data, or disable security measures. All local commands (make, docker-compose) are standard development practices.

Aucun point d'attention détecté

Exemples

Create user service
Create a new Go API service called user-service with module path github.com/myorg/user-service
Order management microservice
Generate a Go microservice for order management named order-service, module path github.com/company/order-service
Config manager API
Start a new Go API project named config-manager with module github.com/team/config-manager

name: go-api description: Create a new Go API service. Use when starting a new Go service, API project, or microservice. Generates complete boilerplate with local development and observability.

Go API Service

Create a production-ready Go API service.

Instructions

When asked to create a new Go API service:

  1. Ask for the service name (kebab-case, e.g., user-service, config-manager)
  2. Ask for the module path (e.g., github.com/myorg/myservice)
  3. Generate the complete project structure using the templates below
  4. Replace placeholders ({SERVICE_NAME}, {SERVICE_NAME_SNAKE}, {SERVICE_NAME_PASCAL}, {MODULE_PATH}) with appropriate values

Project Structure

Generate the following structure:

{SERVICE_NAME}/
├── cmd/
│   └── api/
│       └── main.go
├── internal/
│   ├── api/
│   │   ├── api.go
│   │   └── README.md
│   ├── config/
│   │   ├── config.go
│   │   └── README.md
│   ├── contextx/
│   │   ├── contextx.go
│   │   └── README.md
│   ├── deps/
│   │   ├── deps.go
│   │   └── README.md
│   ├── env/
│   │   ├── env.go
│   │   └── README.md
│   ├── errorsx/
│   │   ├── errorsx.go
│   │   └── README.md
│   ├── httpx/
│   │   ├── httpx.go
│   │   └── README.md
│   ├── logx/
│   │   ├── logx.go
│   │   └── README.md
│   ├── metrics/
│   │   ├── metrics.go
│   │   └── README.md
│   ├── middleware/
│   │   ├── middleware.go
│   │   └── README.md
│   ├── mysql/
│   │   ├── mysql.go
│   │   └── README.md
│   ├── redis/
│   │   ├── redis.go
│   │   └── README.md
│   └── traces/
│       ├── traces.go
│       └── README.md
├── docs/
│   ├── projects/
│   │   ├── completed/
│   │   └── README.md
│   └── architecture.md
├── e2e/
│   ├── doc.go
│   └── helpers_test.go
├── local/
│   ├── config/
│   │   └── api.json
│   ├── mysql/
│   │   ├── docker-compose.yml
│   │   └── initdb.d/
│   │       └── 01-schema.sql
│   └── observability/
│       └── docker-compose.yaml
├── scripts/
│   └── .gitkeep
├── go.mod
├── go.sum
├── Makefile
├── CLAUDE.md
└── README.md

Key Patterns

Clean Architecture

handlers (HTTP) → service (business logic) → repository (data) → model (entities)

Package Naming

Use x suffix for packages that shadow stdlib: logx, httpx, timex, errorsx, contextx

Error Handling

return nil, fmt.Errorf("service: failed to create config: %w", err)

Structured Logging

logger.LogAttrs(ctx, slog.LevelError, "create_config",
    slog.String("config_id", configID),
    slog.Any("err", err),
)

Tracing

spanFunc := func(ctx context.Context) error {
    traces.AddAttributesToCurrentSpan(ctx,
        attribute.String("config_id", configID),
    )
    // ... operation
    return nil
}
err := traces.WithSpan(ctx, s.tracer, "service.CreateConfig", spanFunc)

Templates

When generating files, use the templates in the templates/ directory:

Running Locally

After generation:

# First-time setup
make tools-install

# Start full stack (API + MySQL + Redis + Observability)
make run

# Run tests
make test

# Run integration tests
make test-integration

# Run all linters
make lint-all

Documentation

  • Place all documentation in docs/
  • Project plans go in docs/projects/
  • Move completed plans to docs/projects/completed/
  • Each internal package MUST have a README.md explaining its purpose and usage
Skills similaires