Skip to main content

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.

Gofiber Logo

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.

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.