go-fiber-backend-development
Use when building Go backend APIs (Fiber v3, Mongo, gRPC).
- License 许可
- Unlicense
- 最近更新
- 2026-11-03
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- go-fiber-backend-development
- description
- Use when building Go backend APIs (Fiber v3, Mongo, gRPC).
02 资源文件 3
- 参考文档references/fiber-v3-gotchas.md3.0 KB
- 参考文档references/mermaid-pitfalls.md1.8 KB
- 参考文档references/mongo-driver-v2-gotchas.md1.8 KB
03 SKILL.md 正文
Go Backend Development (User Stack: Fiber v3)
When to Use
Any Go backend service work for this user: new API services, stack migrations (e.g. stdlib→Fiber), Go interview-challenge deliverables, or reviewing Go code from the Dev/QA/Security personas.
Stack Contract (user's chosen stack — do NOT second-guess)
| Concern | Choice (user-confirmed) | Note |
|---|---|---|
| REST framework | Fiber v3 (github.com/gofiber/fiber/v3) |
User explicitly overrode a stdlib net/http choice — never default back to stdlib/ServeMux |
| Architecture | Hexagonal (ports & adapters): domain/ (stdlib-only) → application/ (use cases + ports) → infrastructure/ (adapters) |
Domain package must have zero external imports |
| Persistence | Official go.mongodb.org/mongo-driver/v2 behind a repository port |
See references/mongo-driver-v2-gotchas.md |
| Auth | golang-jwt/v5 HS256, golang.org/x/crypto/bcrypt |
Custom JWT middleware, NOT jwtware — so REST + gRPC share one verifier |
| gRPC (bonus) | grpc-go on separate port + reflection.Register |
Unary interceptor reads authorization metadata |
| Logging | stdlib log/slog JSON handler |
method/path/status/duration_ms + request_id |
| Testing | stdlib testing + hand-written fakes (no mock lib, no testify) |
Challenge/test convention: standard package |
| Ops | Multi-stage Dockerfile, docker-compose (app+mongo), Makefile, .env gitignored |
Non-root runtime user |
Project Layout (hexagonal, module = repo name)
cmd/api/main.go # composition root: wiring + graceful shutdown (helpers: connectMongo/ensureIndexes/serveFiber/serveGRPC/shutdown)
internal/
domain/ # entities, validation rules, sentinel errors (stdlib-only)
application/ # use cases + port interfaces (UserRepository, TokenManager, PasswordHasher)
infrastructure/
mongodb/ user_repo.go # + user_repo_integration_test.go (//go:build integration)
auth/ bcrypt.go jwt.go
httpapi/ app.go handlers.go middleware.go errors.go
grpcapi/ server.go # + interceptor
config/ logger/
worker/ # background jobs (interval injectable for tests)
testutil/ # fake repo + fake hasher (external test packages to avoid import cycles)
proto/ + gen/ # protoc output (module= flag, commit generated code)
Verification Gate Ladder (run in order, all must pass before commit)
gofmt -l .empty,go vet ./...,go build ./...go test -race -count=1 ./...— all packages greengo test -tags integration -race ./internal/infrastructure/mongodb/(compose Mongo up; per-test throwaway DB)bash scripts/smoke.shvs live compose stack (REST + gRPC + 404/405 + container-health checks)grpcurl -plaintext ...happy path + missing-tokenUnauthenticateddocker stop <api>→ logs show clean shutdown, exit code 0go run golang.org/x/vuln/cmd/govulncheck@latest ./...— 0 reachable (bumpgo.modgo directive/toolchain to clear reachable stdlib vulns)
Pitfalls (details in references/)
- Fiber v3 renames —
c.BodyParser→c.Bind(),c.UserContext()→c.Context(),requestid.HeaderXRequestID→fiber.HeaderXRequestID, noDisableStartupMessage. Full map:references/fiber-v3-gotchas.md - Fiber has no auto-405 — add explicit
app.All(path, methodNotAllowed)for every path with specific methods (test will catch it) - BodyLimit → 413 — server-level
MaxRequestBodySize; route*fiber.Error413 through centralErrorHandlerand map to a contract code (e.g.REQUEST_TOO_LARGE), neverINTERNAL_ERROR - In-container healthchecks — Fiber defaults to
ListenerNetwork: tcp4; busyboxwget localhostresolves::1→ unhealthy. Usefiber.ListenConfig{ListenerNetwork: fiber.NetworkTCP} - mongo-driver v2 —
bson/primitivepackage removed;ObjectIDlives inbsondirectly;mongo.Connect(opts...)takes no ctx. Full map:references/mongo-driver-v2-gotchas.md - JWT hardening —
jwt.WithValidMethods([HS256])+jwt.WithIssuer(...)+jwt.WithExpirationRequired(); login timing oracle → dummy bcrypt compare on unknown email (identical 401 body for both failure paths) - Duplicate-email race — friendly pre-check (409) + unique index as race-proof backstop; ID-shape validation in the domain layer so every adapter behaves identically
- Docker secrets —
.dockerignoremust exclude.env/.git/.agents/tools/or the real JWT secret lands in builder-image layers - Strict JSON decoding — decode
c.Body()withjson.Decoder.DisallowUnknownFields()(rejectspasswordsmuggling on PUT update) - Import cycles in tests —
testutilimportsapplication, so application tests must be external (package application_test) - Mermaid in spec docs — see
references/mermaid-pitfalls.md(braces/arrows in node labels break rendering)
Spec-First Workflow (this user)
Write the spec package BEFORE code, using templates at F:\projects\project_spec\template\ (numbered convention: 01_requirement/011, 02_design/022…, 04_testing/041, 07_pm/072_MM). Self-contained spec folder per service (e.g. .agents/spec/, proposals in .agents/proposal/). Cross-persona handoffs are meeting-minutes docs with DEC/ACT ids; contract changes route back to PO (DEC-H03 pattern) — personas polish HOW, never change WHAT.
04 同仓库更多 Skills
project-spec-docs
Fill/update project_spec docs (templates, MM handoffs).
penpot-mcp
Penpot MCP: connect, verify, and fix streaming via nginx.
nginx-streaming-proxy
Configure nginx for streaming endpoints (SSE, MCP, WS).
branding-ci
Use for brand/CI identity, style guides, and brand docs.
yuanbao
Yuanbao (元宝) groups: @mention users, query info/members.
slidev
Create and present web-based slidedecks for developers using Slidev with Markdown, Vue components, code highlighting, animations, and interactive features. Use when building technical presentations, conference talks, code walkthroughs, teaching materials, or developer decks.