Documentation
¶
Overview ¶
internal/gateway/apikey.go
internal/gateway/gateway.go
internal/gateway/middleware_integration.go
internal/gateway/pipeline.go
internal/gateway/router.go
internal/gateway/validation_example.go
Index ¶
- Variables
- func ExampleValidationSetup() *validation.RequestValidator
- func SetupValidatedRoutes(r chi.Router)
- type APIKey
- type APIKeyManager
- func (m *APIKeyManager) GenerateKey(tenantID string, permissions []string) string
- func (m *APIKeyManager) HasPermission(key, permission string) bool
- func (m *APIKeyManager) Middleware(next http.Handler) http.Handler
- func (m *APIKeyManager) RevokeKey(key string) bool
- func (m *APIKeyManager) ValidateKey(key string) (bool, string)
- type Gateway
- func (g *Gateway) HandleFunc(pattern string, handler http.HandlerFunc)
- func (g *Gateway) RegisterRoute(pattern, handler string)
- func (g *Gateway) Route(path string) string
- func (g *Gateway) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (g *Gateway) WithRateLimit(limiter *RateLimiter, handler http.Handler) http.Handler
- type HeaderTransform
- type Middleware
- type Pipeline
- type RateLimiter
- type Router
- type Transform
- type VersionManager
Constants ¶
This section is empty.
Variables ¶
var CommonValidationRules = map[string]*validation.ValidationRules{ "artifact-upload": { ContentTypes: []string{"application/octet-stream"}, MaxBodySize: 5 * 1024 * 1024 * 1024, Headers: validation.HeaderRules{ Required: []string{"X-Tenant-ID"}, }, }, "list-artifacts": { Query: validation.QueryRules{ Types: map[string]validation.ParamType{ "limit": validation.ParamTypeInt, }, Ranges: map[string]validation.Range{ "limit": {Min: 1, Max: 1000}, }, }, }, }
Example validation rules for common operations
Functions ¶
func ExampleValidationSetup ¶
func ExampleValidationSetup() *validation.RequestValidator
Example of how to use the validation layer
func SetupValidatedRoutes ¶
SetupValidatedRoutes adds validation to your API routes
Types ¶
type APIKey ¶
type APIKey struct {
Key string
TenantID string
Permissions []string
CreatedAt time.Time
LastUsed time.Time
}
APIKey represents an API key with metadata
type APIKeyManager ¶
type APIKeyManager struct {
// contains filtered or unexported fields
}
APIKeyManager handles API key validation and permissions
func NewAPIKeyManager ¶
func NewAPIKeyManager() *APIKeyManager
NewAPIKeyManager creates a new API key manager
func (*APIKeyManager) GenerateKey ¶
func (m *APIKeyManager) GenerateKey(tenantID string, permissions []string) string
GenerateKey creates a new API key for a tenant
func (*APIKeyManager) HasPermission ¶
func (m *APIKeyManager) HasPermission(key, permission string) bool
HasPermission checks if a key has a specific permission
func (*APIKeyManager) Middleware ¶
func (m *APIKeyManager) Middleware(next http.Handler) http.Handler
Middleware validates API keys from request headers
func (*APIKeyManager) RevokeKey ¶
func (m *APIKeyManager) RevokeKey(key string) bool
RevokeKey removes an API key
func (*APIKeyManager) ValidateKey ¶
func (m *APIKeyManager) ValidateKey(key string) (bool, string)
ValidateKey checks if a key is valid and returns the tenant ID
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway handles API routing
func (*Gateway) HandleFunc ¶
func (g *Gateway) HandleFunc(pattern string, handler http.HandlerFunc)
HandleFunc registers an HTTP handler function for a pattern
func (*Gateway) RegisterRoute ¶
RegisterRoute registers a route pattern with a handler name
func (*Gateway) ServeHTTP ¶
func (g *Gateway) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler interface
func (*Gateway) WithRateLimit ¶
WithRateLimit adds rate limiting to the gateway
type HeaderTransform ¶
HeaderTransform adds or removes headers
type Middleware ¶
Middleware is a function that wraps an http.Handler
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline manages middleware execution order
func (*Pipeline) ServeHTTP ¶
func (p *Pipeline) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP allows Pipeline to be used as an http.Handler
func (*Pipeline) Use ¶
func (p *Pipeline) Use(middleware Middleware)
Use adds a middleware to the pipeline
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter provides rate limiting functionality
func NewRateLimiter ¶
func NewRateLimiter(limit int, window time.Duration) *RateLimiter
NewRateLimiter creates a new rate limiter
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(key string) bool
Allow checks if a request should be allowed
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router handles request routing and transformation
func (*Router) AddBackend ¶
AddBackend registers a backend for a pattern
func (*Router) AddTransform ¶
AddTransform adds a transformation to the pipeline
func (*Router) SelectBackend ¶
SelectBackend chooses the appropriate backend for a path
type VersionManager ¶
type VersionManager struct {
// contains filtered or unexported fields
}
VersionManager handles API versioning
func NewVersionManager ¶
func NewVersionManager() *VersionManager
NewVersionManager creates a new version manager
func (*VersionManager) ExtractVersion ¶
func (vm *VersionManager) ExtractVersion(path string) string
ExtractVersion extracts the API version from a path
func (*VersionManager) RegisterHandler ¶
func (vm *VersionManager) RegisterHandler(version string, handler http.Handler)
RegisterHandler registers a handler for a specific version
func (*VersionManager) ServeHTTP ¶
func (vm *VersionManager) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler interface
func (*VersionManager) SetDefaultVersion ¶
func (vm *VersionManager) SetDefaultVersion(version string)
SetDefaultVersion sets the default API version
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal/gateway/cache/middleware.go
|
internal/gateway/cache/middleware.go |
|
internal/gateway/metrics/collector.go
|
internal/gateway/metrics/collector.go |
|
internal/gateway/validation/routes.go
|
internal/gateway/validation/routes.go |