What Fiber Does
- Express-like API —
app.Get(),app.Post(), familiar method signatures - Zero memory allocation — routing uses no heap allocations
- Fasthttp — fastest HTTP library for Go (not net/http)
- Middleware — Logger, CORS, Rate Limiter, Compress, ETag, Cache, Helmet
- Template engines — HTML, Pug, Handlebars, Mustache
- WebSocket — built-in WebSocket support
- File upload — multipart form handling
- Static files —
app.Static()built in - Group routing — Express-style route groups
- Hooks — OnRoute, OnName, OnGroup lifecycle hooks
Architecture
Built on Fasthttp (no net/http). Fasthttp reuses request objects and uses byte slices instead of strings to eliminate allocations. Fiber wraps this with an Express-like API. Note: Fasthttp is not fully compatible with Go stdlib middleware (requires adaptation).
Self-Hosting
go build -o server main.go
./server
# Single binary, zero depsKey Features
- Fastest Go web framework (Fasthttp-based)
- Zero allocation routing
- Express-familiar API
- 30+ built-in middleware
- WebSocket support
- Template engines
- Route groups
- Prefork mode for multi-core
- Graceful shutdown
- File upload handling
Comparison
| Framework | HTTP Engine | Allocations | API Style |
|---|---|---|---|
| Fiber | Fasthttp | Zero | Express |
| Gin | net/http + httprouter | Low | Express-like |
| Echo | net/http | Low | Express-like |
| Chi | net/http | Low | stdlib |
| stdlib net/http | net/http | Variable | Raw |
常见问题 FAQ
Q: Fiber vs Gin? A: Fiber 基于 Fasthttp(更快但不兼容 stdlib);Gin 基于 net/http(兼容 stdlib middleware)。纯性能选 Fiber,最大兼容性选 Gin。
Q: Fasthttp 限制? A: Fasthttp 不支持 HTTP/2、不能直接用 net/http middleware。需要适配器或放弃部分 stdlib 集成。
Q: 适合什么场景? A: 高 QPS 的 REST API、需要最低延迟的微服务、从 Express.js 迁移到 Go。
来源与致谢 Sources
- Docs: https://docs.gofiber.io
- GitHub: https://github.com/gofiber/fiber
- License: MIT