Documentation
¶
Overview ¶
Package server provides HTTP server functionality using Echo framework. It includes middleware setup, routing, and request handling.
Package server provides request validation functionality. It wraps go-playground/validator with custom validation logic and error formatting.
Index ¶
- func CORS() echo.MiddlewareFunc
- func Logger(log logger.Logger) echo.MiddlewareFunc
- func PerformanceStats() echo.MiddlewareFunc
- func RateLimit(requestsPerSecond int) echo.MiddlewareFunc
- func SetupMiddlewares(e *echo.Echo, log logger.Logger, cfg *config.Config)
- func Timing() echo.MiddlewareFunc
- type FieldError
- type Server
- type ValidationError
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CORS ¶
func CORS() echo.MiddlewareFunc
CORS returns a CORS middleware configured for the application. It allows cross-origin requests with appropriate security headers.
func Logger ¶
func Logger(log logger.Logger) echo.MiddlewareFunc
Logger returns a request logging middleware using structured logging. It logs HTTP requests with method, URI, status, latency, and request ID.
func PerformanceStats ¶
func PerformanceStats() echo.MiddlewareFunc
PerformanceStats returns middleware that initializes operation tracking for each request. It adds both AMQP message counter and database operation counter to the request context that can be incremented by messaging clients and database layer, then logged in the request logger.
func RateLimit ¶
func RateLimit(requestsPerSecond int) echo.MiddlewareFunc
RateLimit returns a rate limiting middleware with the specified requests per second. It limits the number of requests from each IP address to prevent abuse.
func SetupMiddlewares ¶
SetupMiddlewares configures and registers all HTTP middlewares for the Echo server. It sets up CORS, logging, recovery, security headers, rate limiting, and other essential middleware.
func Timing ¶
func Timing() echo.MiddlewareFunc
Timing returns a middleware that adds response time headers to HTTP responses. It measures request processing time and adds an X-Response-Time header.
Types ¶
type FieldError ¶
type FieldError struct {
Field string `json:"field"`
Message string `json:"message"`
Value string `json:"value,omitempty"`
}
FieldError represents a validation error for a specific field. It includes the field name, error message, and the invalid value.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents an HTTP server instance with Echo framework. It manages server lifecycle, configuration, and request handling.
func New ¶
New creates a new HTTP server instance with the given configuration and logger. It initializes Echo with middlewares, error handling, and health check endpoints.
func (*Server) Echo ¶
Echo returns the underlying Echo instance for route registration. This allows modules to register their routes with the server.
type ValidationError ¶
type ValidationError struct {
Errors []FieldError `json:"errors"`
}
ValidationError wraps validation errors with better messages and structured field errors. It provides a standardized format for validation error responses.
func NewValidationError ¶
func NewValidationError(errs validator.ValidationErrors) *ValidationError
NewValidationError creates a ValidationError from go-playground/validator errors. It converts the errors into a more user-friendly format with descriptive messages.
func (*ValidationError) Error ¶
func (ve *ValidationError) Error() string
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator wraps go-playground/validator with custom validation logic. It provides request validation functionality with custom validators.
func NewValidator ¶
func NewValidator() *Validator
NewValidator creates a new Validator instance with custom validation rules registered.