Documentation
¶
Overview ¶
Package http provides common HTTP server utilities for EVE services. This package includes standard middleware, health checks, and server setup patterns used across the EVE ecosystem.
Index ¶
- func APIKeyMiddleware(apiKey string) echo.MiddlewareFunc
- func CustomHTTPErrorHandler(err error, c echo.Context)
- func GracefulShutdown(e *echo.Echo, timeout time.Duration) error
- func HealthCheckHandler(serviceName, version string) echo.HandlerFunc
- func HealthCheckHandlerWithDetails(serviceName, version string, detailsFunc func() map[string]interface{}) echo.HandlerFunc
- func JSONContentTypeMiddleware() echo.MiddlewareFunc
- func NewEchoServer(config ServerConfig) *echo.Echo
- func SecurityHeadersMiddleware() echo.MiddlewareFunc
- func StartServer(e *echo.Echo, config ServerConfig) error
- type ErrorResponse
- type HealthResponse
- type Request
- type Response
- type ServerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func APIKeyMiddleware ¶ added in v0.0.28
func APIKeyMiddleware(apiKey string) echo.MiddlewareFunc
APIKeyMiddleware creates a middleware that validates API keys
func CustomHTTPErrorHandler ¶ added in v0.0.28
CustomHTTPErrorHandler provides a standard error handler for Echo
func GracefulShutdown ¶ added in v0.0.28
GracefulShutdown performs a graceful shutdown of the Echo server
func HealthCheckHandler ¶ added in v0.0.28
func HealthCheckHandler(serviceName, version string) echo.HandlerFunc
HealthCheckHandler returns a standard health check handler
func HealthCheckHandlerWithDetails ¶ added in v0.0.28
func HealthCheckHandlerWithDetails(serviceName, version string, detailsFunc func() map[string]interface{}) echo.HandlerFunc
HealthCheckHandlerWithDetails returns a health check handler with custom details
func JSONContentTypeMiddleware ¶ added in v0.0.28
func JSONContentTypeMiddleware() echo.MiddlewareFunc
JSONContentTypeMiddleware ensures JSON content type for API responses
func NewEchoServer ¶ added in v0.0.28
func NewEchoServer(config ServerConfig) *echo.Echo
NewEchoServer creates a new Echo server with standard middleware
func SecurityHeadersMiddleware ¶ added in v0.0.28
func SecurityHeadersMiddleware() echo.MiddlewareFunc
SecurityHeadersMiddleware adds security headers to responses
func StartServer ¶ added in v0.0.28
func StartServer(e *echo.Echo, config ServerConfig) error
StartServer starts an Echo server with graceful shutdown support
Types ¶
type ErrorResponse ¶ added in v0.0.28
type ErrorResponse struct {
Error string `json:"error"`
Message string `json:"message,omitempty"`
Details map[string]interface{} `json:"details,omitempty"`
}
ErrorResponse represents a standard error response
type HealthResponse ¶ added in v0.0.28
type HealthResponse struct {
Status string `json:"status"`
Service string `json:"service,omitempty"`
Version string `json:"version,omitempty"`
Details map[string]interface{} `json:"details,omitempty"`
}
HealthResponse represents a health check response
type Request ¶
type Request struct {
// HTTP basics
Method string // GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
URL string // Target URL
// Headers and authentication
Headers map[string]string // HTTP headers
// Request body options
JSONBody string // JSON body for application/json requests
FormData map[string]string // Form data (key-value pairs)
Files map[string]string // Files to upload (form field -> file path)
RawBody []byte // Raw body bytes (for custom content types)
// Response handling
SaveTo string // Save response to file (optional)
// Network configuration
Timeout int // Timeout in seconds (0 = default 30s)
FollowRedirect bool // Follow HTTP redirects (default: true)
MaxRedirects int // Maximum number of redirects (default: 10)
// Retry configuration
RetryCount int // Number of retries on failure (default: 0)
RetryBackoff string // "exponential" or "linear" (default: "exponential")
RetryInterval time.Duration // Initial retry interval (default: 1s)
// Caching
UseCache bool // Enable HTTP caching (ETag, Last-Modified)
CacheValidator string // Custom cache validation logic
// TLS/SSL
InsecureSkipVerify bool // Skip TLS certificate verification (dangerous!)
// Advanced
UserAgent string // Custom User-Agent header
Proxy string // HTTP proxy URL
}
Request represents an HTTP operation with all configuration options
func FromSemanticRequest ¶
func FromSemanticRequest(sr *semantic.SemanticRequest) *Request
FromSemanticRequest creates a Request from Schema.org representation
func NewRequest ¶
NewRequest creates a new Request with sensible defaults
func (*Request) ToSemanticRequest ¶
func (r *Request) ToSemanticRequest() *semantic.SemanticRequest
ToSemanticRequest converts a Request to Schema.org DigitalDocument representation
type Response ¶
type Response struct {
StatusCode int // HTTP status code
Status string // HTTP status message
Headers map[string]string // Response headers
Body []byte // Response body
BodyString string // Response body as string
FromCache bool // Whether response came from cache
Duration time.Duration // Request duration
}
Response represents an HTTP response with metadata
func (*Response) IsClientError ¶
IsClientError returns true if status code is 4xx
func (*Response) IsRedirect ¶
IsRedirect returns true if status code is 3xx
func (*Response) IsServerError ¶
IsServerError returns true if status code is 5xx
func (*Response) ToSemanticResponse ¶
func (r *Response) ToSemanticResponse() *semantic.SemanticResponse
ToSemanticResponse converts a Response to Schema.org representation
type ServerConfig ¶ added in v0.0.28
type ServerConfig struct {
Port int
Debug bool
BodyLimit string // e.g., "100M"
ReadTimeout time.Duration
WriteTimeout time.Duration
ShutdownTimeout time.Duration
AllowedOrigins []string // For CORS
RateLimit float64 // Requests per second (0 = no limit)
}
ServerConfig contains configuration for creating an Echo server
func DefaultServerConfig ¶ added in v0.0.28
func DefaultServerConfig() ServerConfig
DefaultServerConfig returns a server config with sensible defaults