mcpField
F
fiber

fiber

github.com/claude-dev-suiteDevelopment4652 installsUpdated 2d ago
Repository

About fiber

fiber is a quick-reference skill for developers building Go web applications with Fiber. It covers application setup, routing, request handling, middleware, configuration, and production checks.

Key features

  1. 01Fiber 应用配置与路由
  2. 02路径、查询参数和请求体处理
  3. 03中间件使用模式
  4. 04健康检查与就绪端点
  5. 05生产环境检查清单

Use cases

  1. 01搭建 Fiber Web 应用基础结构
  2. 02实现路由并读取请求数据
  3. 03配置恢复、CORS 和限流中间件
  4. 04检查服务健康状态与生产配置

MCP support

README 提到可通过 mcp__documentation__fetch_docs 获取 Fiber 文档;未说明该技能提供 MCP 服务或客户端功能。

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/claude-dev-suite/claude-dev-suite --skill fiber

After installing, type/fiberin Claude Code to confirm it loaded.

Bundled filesadvanced.md

Details

From the project README

Fiber Core Knowledge

Full Reference: See advanced.md for validation with go-playground/validator, WebSocket setup, custom error handling, prefork mode, and graceful shutdown.

Deep Knowledge: Use mcp__documentation__fetch_docs with technology: fiber for comprehensive documentation.

Basic Setup

package main

import "github.com/gofiber/fiber/v2"

func main() {
    app := fiber.New()

    app.Get("/", func(c *fiber.Ctx) error {
        return c.SendString("Hello, World!")
    })

    app.Listen(":8080")
}

Configuration

app := fiber.New(fiber.Config{
    Prefork:       true,               // Multiple processes
    StrictRouting: true,               // /foo != /foo/
    CaseSensitive: true,               // /Foo != /foo
    BodyLimit:     4 * 1024 * 1024,    // 4MB
    ReadTimeout:   10 * time.Second,
    WriteTimeout:  10 * time.Second,
})

Routing

app.Get("/users", listUsers)
app.Get("/users/:id", getUser)
app.Post("/users", createUser)
app.Put("/users/:id", updateUser)
app.Delete("/users/:id", deleteUser)

// Path parameters
app.Get("/users/:id", func(c *fiber.Ctx) error {
    id := c.Params("id")
    return c.JSON(fiber.Map{"id": id})
})

// Optional parameter
app.Get("/users/:name?", func(c *fiber.Ctx) error {
    name := c.Params("name", "anonymous")
    return c.JSON(fiber.Map{"name": name})
})

// Route groups
api := app.Group("/api")
v1 := api.Group("/v1")
v1.Get("/users", listUsersV1)

Context - Request Data

app.Post("/users", func(c *fiber.Ctx) error {
    // Path params
    id := c.Params("id")
    idInt, _ := c.ParamsInt("id")

    // Query params
    page := c.Query("page", "1")
    pageInt := c.QueryInt("page", 1)

    // Headers
    auth := c.Get("Authorization")

    // Cookies
    session := c.Cookies("session_id")

    return c.SendStatus(fiber.StatusOK)
})

Body Parsing

type CreateUserRequest struct {
    Name  string `json:"name"`
    Email string `json:"email"`
}

app.Post("/users", func(c *fiber.Ctx) error {
    var req CreateUserRequest
    if err := c.BodyParser(&req); err != nil {
        return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
            "error": err.Error(),
        })
    }
    return c.Status(fiber.StatusCreated).JSON(req)
})

Middleware

import (
    "github.com/gofiber/fiber/v2/middleware/logger"
    "github.com/gofiber/fiber/v2/middleware/recover"
    "github.com/gofiber/fiber/v2/middleware/cors"
    "github.com/gofiber/fiber/v2/middleware/limiter"
)

app.Use(recover.New())
app.Use(logger.New())

app.Use(cors.New(cors.Config{
    AllowOrigins: "https://example.com",
    AllowMethods: "GET,POST,PUT,DELETE",
}))

app.Use(limiter.New(limiter.Config{
    Max:        100,
    Expiration: 1 * time.Minute,
}))

Health Checks

app.Get("/health", func(c *fiber.Ctx) error {
    return c.JSON(fiber.Map{"status": "healthy"})
})

app.Get("/ready", func(c *fiber.Ctx) error {
    if err := db.Ping(); err != nil {
        return c.Status(fiber.StatusServiceUnavailable).JSON(fiber.Map{
            "status": "not ready",
        })
    }
    return c.JSON(fiber.Map{"status": "ready"})
})

When NOT to Use This Skill

  • Gin projects - Gin has different context API
  • Echo projects - Echo has different middleware patterns
  • Chi projects - Chi is stdlib-compatible
  • Standard net/http required - Fiber uses fasthttp, not net/http
  • gRPC services - Fiber doesn't support gRPC

Anti-Patterns

Anti-PatternWhy It's BadSolution
Not calling c.Next() in middlewareBreaks middleware chainAlways call c.Next() unless stopping
Using c.Body() multiple timesBody is consumedStore body in variable first
Missing error handlingSilent failuresCheck BodyParser() return value
Not setting Prefork carefullyMay cause issues with stateOnly use Prefork without shared state
No rate limitingDDoS vulnerabilityUse limiter middleware

Quick Troubleshooting

ProblemDiagnosisFix
Route not foundWrong method or pathCheck exact route registration
Body parsing failsWrong content-typeEnsure Content-Type header is correct
CORS errorsNot configuredUse cors.New() middleware
Middleware not executingWrong orderPlace before route handlers
Prefork issuesShared state problemsAvoid shared mutable state with Prefork

Production Checklist

  • Recovery middleware enabled
  • CORS configured
  • Rate limiting enabled
  • Request body size limit set
  • Timeouts configured
  • Structured logging
  • Health/readiness endpoints
  • Graceful shutdown
  • Input validation

Reference Documentation

Comments

Markdown supported