Gofiber Web Framework
Gofiber Web Framework
High-performance web framework for the Control Plane's API services
The Control Plane uses Gofiber v2.52.8 as its primary HTTP framework, particularly in the file-manager and secret-manager components.
Performance-focused HTTP framework
Gofiber is an Express-inspired web framework for Go built on top of Fasthttp, providing exceptional performance while maintaining developer-friendly APIs.
Introduction to Gofiberโ
Gofiber is an Express-inspired web framework for Go that's built on top of Fasthttp, the fastest HTTP engine for Go. It provides a robust set of features with minimal overhead and maximum performance.
Why Gofiber?โ
โก Performance
Built on Fasthttp, offering high throughput and low latency for API services.
๐ชถ Low memory footprint
Efficient resource utilization, critical for containerized deployments.
๐ Middleware support
Extensible middleware system for cross-cutting concerns like logging and authentication.
๐งฉ Express-like API
Familiar for developers with Node.js experience, reducing learning curve.
๐๏ธ Route grouping
Structured API organization through logical grouping of related endpoints.
Routing best practices
Group related endpoints under a common prefix and apply shared middleware to route groups rather than individual routes. This keeps your code DRY and makes middleware management more maintainable.
JWT Authenticationโ
Secure by default
All API endpoints in the Control Plane are secured by JWT authentication middleware by default, with specific public routes explicitly marked as unauthenticated.
Custom Middlewareโ
The project includes several custom middleware components built on Gofiber:
๐ Request Logging
Structured logging of requests with contextual information like request ID, user, and timing.
๐ Metrics Collection
Prometheus metrics for request counts, latency, and error rates.
๐ก๏ธ Panic Recovery
Gracefully handles panics in request handlers, preventing service crashes.
๐ CORS Handling
Configures Cross-Origin Resource Sharing for browser security.
๐งฉ Context Injection
Injects business context like team ID and environment into request context.
Integration with OpenAPIโ
Code generation
The Control Plane uses OpenAPI specifications to generate server stubs, ensuring API documentation and implementation are always in sync.
Error Handlingโ
Consistent error responses
Always use Gofiber's structured error handling to ensure consistent error responses across all APIs. This improves client experience and debuggability.
Performance Configurationsโ
Performance Settings
Key performance configurations include:
- Disabling prefork for containerized environments
- Setting strict routing for API clarity
- Using case-sensitive routes for correctness
- Custom JSON encoders for performance
- Custom error handlers for consistent responses
Benchmarks
Gofiber offers excellent performance metrics:
- ~30% faster than Echo or Gin
- ~40-45% less memory usage
- ~10x the throughput of standard net/http
- Zero memory allocations in hot paths
- Optimized for high-concurrency workloads
Best Practicesโ
Gofiber best practices
The Control Plane follows these best practices for Gofiber development to ensure maintainable and performant APIs.
๐๏ธ Route Organization
Group related routes and use consistent URL patterns across all APIs.
๐ Security First
Always apply authentication and authorization middleware to protect resources.
๐ Structured Logging
Use consistent logging patterns with appropriate context for observability.
๐งช Testing
Write comprehensive API tests using Fiber's test utilities.
โ๏ธ Configuration
Use environment variables for all configurable aspects of the server.
๐ Metrics
Instrument all endpoints with Prometheus metrics for monitoring.
Related Resourcesโ
Go Language
Learn about the foundational language used in the Control Plane.
JWT Authentication
Explore how JWT is used for authentication in the Control Plane.