skeleton-api-go-skill

📁 joseluis21/go-api-skills 📅 3 days ago
2
总安装量
2
周安装量
#73815
全站排名
安装命令
npx skills add https://github.com/joseluis21/go-api-skills --skill skeleton-api-go-skill

Agent 安装分布

amp 2
github-copilot 2
codex 2
kimi-cli 2
gemini-cli 2
cursor 2

Skill 文档

Skeleton API Go Skill

This skill helps you rapidly scaffold new Go API projects with a proven, production-ready structure.

What It Sets Up

A complete Go API project with:

Component Tech
Framework Fiber (lightweight, fast HTTP)
Database MongoDB
Storage AWS S3 / Cloudflare R2
Docker Multi-stage builds, docker-compose
Structure Layered architecture (routes, middleware, services)
Validation Go Playground Validator
Logging Structured logging (slog + JSON)
UUID UUIDv7 generation

Directory Structure

project-name/
├── cmd/api/main.go                 # Entry point
├── internal/
│   ├── container/                  # Dependency injection
│   ├── routes/                      # Public & private routes
│   ├── middleware/                  # Request validation, auth, etc.
│   ├── server/                      # Server initialization
│   ├── libraries/
│   │   ├── cloudflare/r2_client.go
│   │   └── mongodb/mongodb_client.go
│   └── shared/
│       ├── response/                # HTTP response helpers
│       ├── utils/                   # Utilities (MongoDB, R2, UUID, etc.)
│       └── validatorapi/            # Validation helpers
├── .env.example
├── Dockerfile
├── docker-compose.yml
├── go.mod & go.sum
└── README.md

Usage

When asked to “create a new Go API project” or similar, Claude will:

Step 1: Gather Requirements

  • Project name
  • Go module name (e.g., github.com/username/project)
  • Base features (MongoDB, R2, routes structure)

Step 2: Generate Structure

This skill automates:

  • Creating directory structure
  • Generating go.mod with core dependencies
  • Creating boilerplate files (main.go, server setup, routes)
  • Docker and docker-compose files
  • Environment template (.env.example)

Step 3: Provide Setup Steps

Clear commands to initialize and run the project:

cd project-name
go mod tidy
docker-compose up -d      # If using MongoDB locally
go run ./cmd/api/main.go

Key Features Included

1. Layered Architecture

  • Clean separation: routes → middleware → handlers → services
  • Easy to test and maintain

2. Dependency Injection (container.go)

  • Centralized container for all dependencies
  • Pass services cleanly through the app

3. Shared Response Format

  • Consistent JSON responses
  • Error handling with proper HTTP status codes

4. Validation

  • Input validation middleware
  • Built-in request validation helpers

5. Logging

  • Structured, JSON-based logging (slog)
  • Debug, info, error levels

6. Database & Storage Setup

  • MongoDB client initialization
  • R2/S3 client initialization
  • Ready-to-use utility functions

Implementation Details

The skill will generate:

  • main.go: Loads .env, initializes MongoDB, R2, sets up server
  • server.go: Fiber server with routes and middleware registration
  • container.go: Dependency container pattern
  • routes files: Separated public and private routes
  • middleware/validator.go: Request validation middleware
  • Dockerfile: Multi-stage build (builder + runtime Alpine)
  • docker-compose.yml: Local MongoDB setup
  • .env.example: Template for environment variables

Customization Points

Once generated, you can easily:

  • Add more routes (edit internal/routes/)
  • Add middleware (edit internal/middleware/)
  • Change database operations (edit internal services)
  • Modify Docker settings (edit Dockerfile & docker-compose.yml)

Next Steps After Generation

  1. Replace placeholder names in files (project name, module name)
  2. Update README.md with your specific API endpoints
  3. Add domain-specific handlers in internal/routes/
  4. Create service layer for business logic
  5. Implement actual database models in MongoDB