fiber-logging-and-project-structure
БесплатноЗапускает вложенные скриптыНе проверенApplies best practices for logging (zerolog/zap), project structure (cmd/internal/pkg), middleware registration order, and environment configuration in Go…
от oimiragieo★ 48 звёзд на GitHubОб этом скилле
Fiber Logging And Project Structure Skill
Project Structure (Standard Go Layout)
- Organize all Fiber applications using:
cmd/<appname>/main.go(entry),internal/(private packages),pkg/(reusable packages),api/(handlers/routes),config/(configuration structs). - Never put business logic in
cmd/— keepmain.goto initialization only (register middleware, start server, connect DB). - Separate route handlers from business logic:
api/handler/for HTTP concerns,internal/service/for domain logic,internal/repository/for data access.
Logging
- Use structured logging:
zerolog(preferred for Fiber) orzap. Never usefmt.Printlnor stdliblogin production handlers. - Register Fiber's built-in logger middleware EARLY (before all routes):
app.Use(logger.New()). - Fiber v3 logger middleware: import from
github.com/gofiber/fiber/v3/middleware/logger. - Add correlation IDs in middleware using
ctx.Locals("requestID", uuid.New())and include in every log entry. - Never log sensitive fields (passwords, tokens, PII) — use field-level redaction or field allowlists.
Middleware Registration Order
- Register global middleware before routes: Logger → RequestID → CORS → RateLimiter → Auth → Routes.
- Middleware registered via
app.Use()applies to all subsequent routes; placement matters. - Route-specific middleware: apply as a second argument to
app.Get("/path", authMiddleware, handler).
Environment Configuration
- Load config at startup via
viper,envconfig, orgodotenv— never reados.Getenv()scattered in handlers. - Define a typed config struct:
type Config struct { Port string \env:"PORT" envDefault:"3000"` }`. - Provide
.env.examplewith all required variables; never commit.envfiles. - Fail fast on missing required config: panic or
log.Fatalduring startup if required env vars are absent.
Error Handling
- Return
fiber.NewError(fiber.StatusBadRequest, "message")from handlers for HTTP errors. - Use a global error handler via
app.Config().ErrorHandlerto produce consistent JSON error responses. - Never expose internal error details or stack traces in production error responses.
import ( "log" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/logger" "github.com/gofiber/fiber/v2/middleware/requestid" "myapp/internal/config" "myapp/api/routes" )
func main() { cfg := config.Load() // typed config, fails fast on missing vars
app := fiber.New(fiber.Config{
ErrorHandler: func(c *fiber.Ctx, err error) error {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
},
})
// Middleware: register BEFORE routes
app.Use(requestid.New())
app.Use(logger.New(logger.Config{
Format: "${time} ${method} ${path} ${status} ${latency}\n",
}))
routes.Register(app) // all routes in internal/api/routes/
log.Fatal(app.Listen(cfg.Port))
}
// internal/config/config.go — typed config type Config struct { Port string `env:"PORT" envDefault:":3000"` DBUrl string `env:"DATABASE_URL,required"` }
</examples>
## Iron Laws
1. **ALWAYS** use structured logging (zerolog or logrus with JSON output) — never use `fmt.Println` or `log.Printf` in production Fiber applications; unstructured logs cannot be parsed by log aggregators.
2. **NEVER** put business logic in route handlers — always call a service/controller layer; route handlers must only handle HTTP concerns (parsing, validation, response writing).
3. **ALWAYS** use Fiber's `ctx.Locals()` for request-scoped values (user ID, trace ID) — never pass request-scoped data via global variables or function parameters down the call stack.
4. **NEVER** commit sensitive configuration directly in code — use `envconfig`, `viper`, or environment variables with a `.env.example` template; loaded secrets must never appear in logs.
5. **ALWAYS** organize project structure into `cmd/`, `internal/`, `pkg/` conventions — Fiber projects that put all code in root packages become unmaintainable at scale.
## Anti-Patterns
| Anti-Pattern | Why It Fails | Correct Approach |
| ------------------------------------------- | ---------------------------------------------
Установить fiber-logging-and-project-structure в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteEditВложенные файлы
FAQ
Что делает скилл fiber-logging-and-project-structure?
Applies best practices for logging (zerolog/zap), project structure (cmd/internal/pkg), middleware registration order, and environment configuration in Go Fiber v2/v3 applications.
Как установить скилл fiber-logging-and-project-structure?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл fiber-logging-and-project-structure запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic