Documentation
¶
Overview ¶
Package routing provides HTTP routing and analytics endpoints.
Index ¶
- Variables
- func HandleAgentNewTicket(c *gin.Context)
- func HandleCustomerInfoPanel(c *gin.Context)
- func IntegrateWithExistingSystem(router *gin.Engine, db *sql.DB, jwtManager interface{}) error
- func IsRouteRegistered(method, path string) bool
- func LoadYAMLRoutes(router *gin.Engine, routesPath string, registry *HandlerRegistry) error
- func LoadYAMLRoutesForTesting(router *gin.Engine) error
- func LoadYAMLRoutesFromGlobalMap(router *gin.Engine, routesPath string) error
- func MigrateExistingRoutes() error
- func RegisterAPIHandlers(registry *HandlerRegistry, apiHandlers map[string]gin.HandlerFunc)
- func RegisterExistingHandlers(registry *HandlerRegistry)
- func RegisterHandler(name string, handler gin.HandlerFunc)
- func RegisterManualRoute(method, path string)
- func SetDynamicFieldLoader(loader DynamicFieldLoader)
- func SyncHandlersToGlobalMap(registry *HandlerRegistry)
- type AlertRule
- type DurationBreakdown
- type DynamicFieldLoader
- type EventType
- type FeatureFlag
- type FileRouteStore
- func (s *FileRouteStore) Apply(ctx context.Context, config *RouteConfig) error
- func (s *FileRouteStore) Delete(ctx context.Context, namespace, name string) error
- func (s *FileRouteStore) Get(ctx context.Context, namespace, name string) (*RouteConfig, error)
- func (s *FileRouteStore) List(ctx context.Context, namespace string) ([]*RouteConfig, error)
- func (s *FileRouteStore) Start(ctx context.Context) error
- func (s *FileRouteStore) Stop() error
- func (s *FileRouteStore) Watch(ctx context.Context, namespace string) (<-chan RouteEvent, error)
- type HandlerFunc
- type HandlerRegistry
- func (r *HandlerRegistry) Clear()
- func (r *HandlerRegistry) Get(name string) (gin.HandlerFunc, error)
- func (r *HandlerRegistry) GetAllHandlers() map[string]gin.HandlerFunc
- func (r *HandlerRegistry) GetHandlerChain(middlewareNames []string, handlerName string) ([]gin.HandlerFunc, error)
- func (r *HandlerRegistry) GetMiddleware(name string) (gin.HandlerFunc, error)
- func (r *HandlerRegistry) HandlerExists(name string) bool
- func (r *HandlerRegistry) IsFeatureEnabled(name string) bool
- func (r *HandlerRegistry) ListHandlers() []string
- func (r *HandlerRegistry) ListMiddleware() []string
- func (r *HandlerRegistry) MiddlewareExists(name string) bool
- func (r *HandlerRegistry) MustGet(name string) gin.HandlerFunc
- func (r *HandlerRegistry) Override(name string, handler gin.HandlerFunc)
- func (r *HandlerRegistry) OverrideBatch(handlers map[string]gin.HandlerFunc)
- func (r *HandlerRegistry) Register(name string, handler gin.HandlerFunc) error
- func (r *HandlerRegistry) RegisterBatch(handlers map[string]gin.HandlerFunc) error
- func (r *HandlerRegistry) RegisterMiddleware(name string, middleware gin.HandlerFunc) error
- func (r *HandlerRegistry) RegisterMiddlewareBatch(middlewares map[string]gin.HandlerFunc) error
- func (r *HandlerRegistry) SetFeature(name string, enabled bool)
- type LoaderOption
- type MiddlewareConfig
- type OpenAPIParameter
- type OpenAPISpec
- type ParamConfig
- type PerformanceAnomaly
- type PerformanceReport
- type PerformanceSummary
- type RateLimitConfig
- type RequestLog
- type RequestSample
- type RouteConfig
- type RouteDefinition
- type RouteEvent
- type RouteGroup
- type RouteLoader
- type RouteMetadata
- type RouteMetrics
- type RouteProfile
- type RouteProfiler
- func (rp *RouteProfiler) GenerateReport() *PerformanceReport
- func (rp *RouteProfiler) GetAllProfiles() map[string]*RouteProfile
- func (rp *RouteProfiler) GetAnomalies() []PerformanceAnomaly
- func (rp *RouteProfiler) GetProfile(path, method string) *RouteProfile
- func (rp *RouteProfiler) GetTopSlowest(count int) []*RouteProfile
- func (rp *RouteProfiler) ProfileMiddleware() gin.HandlerFunc
- func (rp *RouteProfiler) RecordDatabaseTime(c *gin.Context, duration time.Duration)
- func (rp *RouteProfiler) RecordExternalTime(c *gin.Context, duration time.Duration)
- type RouteRequest
- type RouteSpec
- type RouteStatistics
- type RouteStats
- type RouteStore
- type RouteTestCase
- type RouteVersion
- type RouteVersionManager
- func (vm *RouteVersionManager) CreateVersion(routes map[string]*RouteConfig, message string) (*RouteVersion, error)
- func (vm *RouteVersionManager) DiffVersions(fromVersion, toVersion string) (*VersionDiff, error)
- func (vm *RouteVersionManager) GetVersion(versionOrHash string) (*RouteVersion, error)
- func (vm *RouteVersionManager) ListVersions() []*RouteVersion
- func (vm *RouteVersionManager) Rollback(versionOrHash string) error
- func (vm *RouteVersionManager) SetAutoCommit(enabled bool)
- type SimpleRouteManager
- type SystemStats
- type VersionDiff
- type VersionStats
Constants ¶
This section is empty.
Variables ¶
var GlobalHandlerMap = make(map[string]gin.HandlerFunc)
Global handler map that will be populated by the API package.
Functions ¶
func HandleAgentNewTicket ¶
HandleAgentNewTicket renders the new ticket form with proper nav context.
func HandleCustomerInfoPanel ¶
HandleCustomerInfoPanel returns partial with customer details or unregistered notice.
func IntegrateWithExistingSystem ¶
with the existing handler functions.
func IsRouteRegistered ¶
IsRouteRegistered checks if a route is already registered.
func LoadYAMLRoutes ¶
func LoadYAMLRoutes(router *gin.Engine, routesPath string, registry *HandlerRegistry) error
LoadYAMLRoutes is a package-level function that creates a RouteLoader and loads all routes.
func LoadYAMLRoutesForTesting ¶
LoadYAMLRoutesForTesting loads YAML routes for test/development scenarios. This function auto-discovers the routes directory and uses the standard middleware. Tests MUST authenticate properly - there is NO auth bypass. This is the ONLY function that should be used for loading YAML routes in tests - do not use internal/api/yaml_router_loader.go directly (it's only for manifest generation).
func LoadYAMLRoutesFromGlobalMap ¶
LoadYAMLRoutesFromGlobalMap loads YAML routes using the GlobalHandlerMap as the handler source. This is the preferred method - handlers self-register via init() into GlobalHandlerMap, eliminating the need for manual handler registration in main.go.
func MigrateExistingRoutes ¶
func MigrateExistingRoutes() error
MigrateExistingRoutes helps migrate existing hardcoded routes to YAML.
func RegisterAPIHandlers ¶
func RegisterAPIHandlers(registry *HandlerRegistry, apiHandlers map[string]gin.HandlerFunc)
RegisterAPIHandlers registers API handlers with the registry.
func RegisterExistingHandlers ¶
func RegisterExistingHandlers(registry *HandlerRegistry)
RegisterExistingHandlers registers existing handlers with the registry.
func RegisterHandler ¶
func RegisterHandler(name string, handler gin.HandlerFunc)
RegisterHandler allows the API package to register handlers.
func RegisterManualRoute ¶
func RegisterManualRoute(method, path string)
This should be called whenever routes are registered manually.
func SetDynamicFieldLoader ¶
func SetDynamicFieldLoader(loader DynamicFieldLoader)
SetDynamicFieldLoader sets the function used to load dynamic fields (called by api package).
func SyncHandlersToGlobalMap ¶
func SyncHandlersToGlobalMap(registry *HandlerRegistry)
This ensures YAML routes can find handlers registered via RegisterAPIHandlers.
Types ¶
type AlertRule ¶
type AlertRule struct {
Name string
Description string
Check func(*RouteProfile) bool
Message func(*RouteProfile) string
}
AlertRule defines conditions for performance alerts.
type DurationBreakdown ¶
type DurationBreakdown struct {
Middleware time.Duration `json:"middleware"`
Handler time.Duration `json:"handler"`
Database time.Duration `json:"database"`
External time.Duration `json:"external"`
Serialization time.Duration `json:"serialization"`
}
DurationBreakdown shows where time was spent.
type DynamicFieldLoader ¶
DynamicFieldLoader is a function type for loading dynamic fields to avoid import cycles.
type FeatureFlag ¶
type FeatureFlag struct {
Name string `yaml:"name"`
Enabled bool `yaml:"enabled"`
Description string `yaml:"description"`
EnabledFor []string `yaml:"enabledFor"` // Specific tenants or users
Percentage int `yaml:"percentage"` // For gradual rollout
StartDate time.Time `yaml:"startDate"`
EndDate time.Time `yaml:"endDate"`
}
FeatureFlag represents a feature flag configuration.
type FileRouteStore ¶
type FileRouteStore struct {
// contains filtered or unexported fields
}
This provides k8s-style API over YAML files for docker-compose deployments.
func NewFileRouteStore ¶
func NewFileRouteStore(routesDir string, router *gin.Engine, registry *HandlerRegistry) *FileRouteStore
NewFileRouteStore creates a new file-based route store.
func (*FileRouteStore) Apply ¶
func (s *FileRouteStore) Apply(ctx context.Context, config *RouteConfig) error
Apply creates or updates a route configuration by writing to file.
func (*FileRouteStore) Delete ¶
func (s *FileRouteStore) Delete(ctx context.Context, namespace, name string) error
Delete removes a route configuration by deleting the file.
func (*FileRouteStore) Get ¶
func (s *FileRouteStore) Get(ctx context.Context, namespace, name string) (*RouteConfig, error)
Get retrieves a route configuration by namespace and name.
func (*FileRouteStore) List ¶
func (s *FileRouteStore) List(ctx context.Context, namespace string) ([]*RouteConfig, error)
List returns all route configurations in a namespace.
func (*FileRouteStore) Start ¶
func (s *FileRouteStore) Start(ctx context.Context) error
Start initializes the file watcher and loads existing routes.
func (*FileRouteStore) Stop ¶
func (s *FileRouteStore) Stop() error
Stop shuts down the file watcher.
func (*FileRouteStore) Watch ¶
func (s *FileRouteStore) Watch(ctx context.Context, namespace string) (<-chan RouteEvent, error)
Watch returns a channel that receives route change events.
type HandlerFunc ¶
type HandlerFunc gin.HandlerFunc
HandlerFunc is the standard handler function type.
type HandlerRegistry ¶
type HandlerRegistry struct {
// contains filtered or unexported fields
}
HandlerRegistry manages the mapping between handler names and functions.
func NewHandlerRegistry ¶
func NewHandlerRegistry() *HandlerRegistry
NewHandlerRegistry creates a new handler registry.
func (*HandlerRegistry) Clear ¶
func (r *HandlerRegistry) Clear()
Clear removes all registered handlers and middleware.
func (*HandlerRegistry) Get ¶
func (r *HandlerRegistry) Get(name string) (gin.HandlerFunc, error)
Get retrieves a handler by name. Falls back to GlobalHandlerMap if not found in registry (for init-registered handlers).
func (*HandlerRegistry) GetAllHandlers ¶
func (r *HandlerRegistry) GetAllHandlers() map[string]gin.HandlerFunc
GetAllHandlers returns all registered handlers as a map.
func (*HandlerRegistry) GetHandlerChain ¶
func (r *HandlerRegistry) GetHandlerChain(middlewareNames []string, handlerName string) ([]gin.HandlerFunc, error)
GetHandlerChain builds a complete handler chain with middleware.
func (*HandlerRegistry) GetMiddleware ¶
func (r *HandlerRegistry) GetMiddleware(name string) (gin.HandlerFunc, error)
GetMiddleware retrieves middleware by name.
func (*HandlerRegistry) HandlerExists ¶
func (r *HandlerRegistry) HandlerExists(name string) bool
HandlerExists checks if a handler is registered.
func (*HandlerRegistry) IsFeatureEnabled ¶
func (r *HandlerRegistry) IsFeatureEnabled(name string) bool
IsFeatureEnabled checks if a feature is enabled.
func (*HandlerRegistry) ListHandlers ¶
func (r *HandlerRegistry) ListHandlers() []string
ListHandlers returns all registered handler names.
func (*HandlerRegistry) ListMiddleware ¶
func (r *HandlerRegistry) ListMiddleware() []string
ListMiddleware returns all registered middleware names.
func (*HandlerRegistry) MiddlewareExists ¶
func (r *HandlerRegistry) MiddlewareExists(name string) bool
MiddlewareExists checks if middleware is registered.
func (*HandlerRegistry) MustGet ¶
func (r *HandlerRegistry) MustGet(name string) gin.HandlerFunc
MustGet retrieves a handler by name, panics if not found.
func (*HandlerRegistry) Override ¶
func (r *HandlerRegistry) Override(name string, handler gin.HandlerFunc)
Override replaces an existing handler or registers a new one.
func (*HandlerRegistry) OverrideBatch ¶
func (r *HandlerRegistry) OverrideBatch(handlers map[string]gin.HandlerFunc)
OverrideBatch replaces multiple existing handlers or registers new ones.
func (*HandlerRegistry) Register ¶
func (r *HandlerRegistry) Register(name string, handler gin.HandlerFunc) error
Register adds a handler to the registry.
func (*HandlerRegistry) RegisterBatch ¶
func (r *HandlerRegistry) RegisterBatch(handlers map[string]gin.HandlerFunc) error
RegisterBatch registers multiple handlers at once.
func (*HandlerRegistry) RegisterMiddleware ¶
func (r *HandlerRegistry) RegisterMiddleware(name string, middleware gin.HandlerFunc) error
RegisterMiddleware adds a middleware to the registry.
func (*HandlerRegistry) RegisterMiddlewareBatch ¶
func (r *HandlerRegistry) RegisterMiddlewareBatch(middlewares map[string]gin.HandlerFunc) error
RegisterMiddlewareBatch registers multiple middleware at once.
func (*HandlerRegistry) SetFeature ¶
func (r *HandlerRegistry) SetFeature(name string, enabled bool)
SetFeature enables or disables a feature flag.
type LoaderOption ¶
type LoaderOption func(*RouteLoader)
LoaderOption is a functional option for RouteLoader.
func WithEnvironment ¶
func WithEnvironment(env string) LoaderOption
WithEnvironment sets the environment for conditional routes.
func WithHotReload ¶
func WithHotReload(enabled bool) LoaderOption
WithHotReload enables hot reload of route configurations.
func WithStrictMode ¶
func WithStrictMode(enabled bool) LoaderOption
WithStrictMode enables strict mode (fail on missing handlers).
type MiddlewareConfig ¶
type MiddlewareConfig struct {
Name string `yaml:"name"`
Enabled bool `yaml:"enabled"`
Config map[string]interface{} `yaml:"config"`
}
MiddlewareConfig defines middleware configuration.
type OpenAPIParameter ¶
type OpenAPIParameter struct {
Name string `yaml:"name"`
In string `yaml:"in"` // path, query, header, cookie
Description string `yaml:"description"`
Required bool `yaml:"required"`
Schema map[string]interface{} `yaml:"schema"`
}
OpenAPIParameter defines an OpenAPI parameter.
type OpenAPISpec ¶
type OpenAPISpec struct {
Summary string `yaml:"summary"`
Description string `yaml:"description"`
Tags []string `yaml:"tags"`
Parameters []OpenAPIParameter `yaml:"parameters"`
RequestBody map[string]interface{} `yaml:"requestBody"`
Responses map[int]string `yaml:"responses"`
Security []map[string][]string `yaml:"security"`
}
OpenAPISpec contains OpenAPI documentation for the route.
type ParamConfig ¶
type ParamConfig struct {
Type string `yaml:"type"` // int, string, uuid, email
Required bool `yaml:"required"`
Default string `yaml:"default"`
Pattern string `yaml:"pattern"`
Min int `yaml:"min"`
Max int `yaml:"max"`
Enum []string `yaml:"enum"`
Transform string `yaml:"transform"` // lowercase, uppercase, trim
Description string `yaml:"description"`
}
ParamConfig defines parameter validation and transformation.
type PerformanceAnomaly ¶
type PerformanceAnomaly struct {
Route string `json:"route"`
Type string `json:"type"`
Severity string `json:"severity"`
Description string `json:"description"`
DetectedAt time.Time `json:"detected_at"`
Evidence string `json:"evidence"`
}
PerformanceAnomaly represents detected performance issues.
type PerformanceReport ¶
type PerformanceReport struct {
GeneratedAt time.Time `json:"generated_at"`
Profiles map[string]*RouteProfile `json:"profiles"`
Summary *PerformanceSummary `json:"summary"`
Anomalies []PerformanceAnomaly `json:"anomalies"`
}
PerformanceReport represents a complete performance analysis.
type PerformanceSummary ¶
type PerformanceSummary struct {
TotalRoutes int `json:"total_routes"`
TotalRequests int64 `json:"total_requests"`
AvgDuration time.Duration `json:"avg_duration"`
ErrorRate float64 `json:"error_rate"`
TopSlowestRoutes []*RouteProfile `json:"top_slowest_routes"`
TopErrorRoutes []*RouteProfile `json:"top_error_routes"`
}
PerformanceSummary contains high-level performance metrics.
type RateLimitConfig ¶
type RateLimitConfig struct {
Requests int `yaml:"requests"`
Period time.Duration `yaml:"period"`
Key string `yaml:"key"` // ip, user, api_key
}
RateLimitConfig defines rate limiting settings.
type RequestLog ¶
type RequestLog struct {
Timestamp time.Time `json:"timestamp"`
Method string `json:"method"`
Path string `json:"path"`
StatusCode int `json:"status_code"`
Duration time.Duration `json:"duration"`
UserAgent string `json:"user_agent"`
IP string `json:"ip"`
}
RequestLog represents a single request log entry.
type RequestSample ¶
type RequestSample struct {
Timestamp time.Time `json:"timestamp"`
Duration time.Duration `json:"duration"`
StatusCode int `json:"status_code"`
BytesIn int64 `json:"bytes_in"`
BytesOut int64 `json:"bytes_out"`
Error string `json:"error,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
Breakdown *DurationBreakdown `json:"breakdown,omitempty"`
}
RequestSample represents a single request measurement.
type RouteConfig ¶
type RouteConfig struct {
APIVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Metadata RouteMetadata `yaml:"metadata"`
Spec RouteSpec `yaml:"spec"`
}
RouteConfig represents a complete route configuration file.
func (*RouteConfig) Validate ¶
func (rc *RouteConfig) Validate() error
Validate checks if the route configuration is valid.
type RouteDefinition ¶
type RouteDefinition struct {
Path string `yaml:"path"`
Method interface{} `yaml:"method"` // Can be string or []string
Handler string `yaml:"handler"`
Handlers map[string]string `yaml:"handlers"` // For multiple methods
Name string `yaml:"name"`
Description string `yaml:"description"`
Permissions []string `yaml:"permissions"`
Features []string `yaml:"features"`
Middleware []string `yaml:"middleware"`
RateLimit *RateLimitConfig `yaml:"rateLimit"`
Condition string `yaml:"condition"`
OpenAPI *OpenAPISpec `yaml:"openapi"`
TestCases []RouteTestCase `yaml:"testCases"`
Params map[string]ParamConfig `yaml:"params"`
}
RouteDefinition represents a single route.
func (*RouteDefinition) GetMethods ¶
func (rd *RouteDefinition) GetMethods() []string
GetMethods returns the HTTP methods for a route definition as a slice.
type RouteEvent ¶
type RouteEvent struct {
Type EventType `json:"type"`
Object *RouteConfig `json:"object"`
OldObject *RouteConfig `json:"oldObject,omitempty"`
}
RouteEvent represents a change to a route configuration.
type RouteGroup ¶
type RouteGroup struct {
Name string `yaml:"name"`
Prefix string `yaml:"prefix"`
Middleware []string `yaml:"middleware"`
Files []string `yaml:"files"` // YAML files to include
Enabled bool `yaml:"enabled"`
}
RouteGroup represents a logical grouping of routes.
type RouteLoader ¶
type RouteLoader struct {
// contains filtered or unexported fields
}
RouteLoader manages loading and registering routes from YAML files.
func NewRouteLoader ¶
func NewRouteLoader(routesPath string, registry *HandlerRegistry, router *gin.Engine, opts ...LoaderOption) (*RouteLoader, error)
NewRouteLoader creates a new route loader.
func (*RouteLoader) Close ¶
func (l *RouteLoader) Close() error
Close closes the route loader and stops watching files.
func (*RouteLoader) GetLoadedRoutes ¶
func (l *RouteLoader) GetLoadedRoutes() map[string]*RouteConfig
GetLoadedRoutes returns information about loaded routes.
func (*RouteLoader) LoadRoutes ¶
func (l *RouteLoader) LoadRoutes() error
LoadRoutes loads all route configurations from the routes directory.
type RouteMetadata ¶
type RouteMetadata struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
Namespace string `yaml:"namespace"`
Enabled bool `yaml:"enabled"`
Version string `yaml:"version"`
Labels map[string]string `yaml:"labels"`
Tenants []string `yaml:"tenants"`
}
RouteMetadata contains metadata about the route group.
type RouteMetrics ¶
type RouteMetrics struct {
// contains filtered or unexported fields
}
RouteMetrics tracks performance and usage metrics for routes.
func GetGlobalMetrics ¶
func GetGlobalMetrics() *RouteMetrics
GetGlobalMetrics returns the global metrics instance.
func InitRouteMetrics ¶
func InitRouteMetrics() *RouteMetrics
InitRouteMetrics initializes the global metrics tracker.
func NewRouteMetrics ¶
func NewRouteMetrics() *RouteMetrics
NewRouteMetrics creates a new route metrics tracker.
func (*RouteMetrics) GetStats ¶
func (rm *RouteMetrics) GetStats() *SystemStats
GetStats returns current statistics.
func (*RouteMetrics) MiddlewareWithMetrics ¶
func (rm *RouteMetrics) MiddlewareWithMetrics(routePath, handlerName string) gin.HandlerFunc
MiddlewareWithMetrics returns a Gin middleware that tracks route metrics.
func (*RouteMetrics) RecordRequest ¶
func (rm *RouteMetrics) RecordRequest(req RouteRequest)
RecordRequest records metrics for a route request.
func (*RouteMetrics) SetupMetricsEndpoints ¶
func (rm *RouteMetrics) SetupMetricsEndpoints(r *gin.Engine)
SetupMetricsEndpoints adds analytics endpoints to the router.
type RouteProfile ¶
type RouteProfile struct {
Path string `json:"path"`
Method string `json:"method"`
Handler string `json:"handler"`
Samples []RequestSample `json:"samples"`
Statistics *RouteStatistics `json:"statistics"`
Recommendations []string `json:"recommendations"`
LastUpdated time.Time `json:"last_updated"`
}
RouteProfile contains performance data for a specific route.
type RouteProfiler ¶
type RouteProfiler struct {
// contains filtered or unexported fields
}
RouteProfiler collects and analyzes route performance metrics.
func NewRouteProfiler ¶
func NewRouteProfiler() *RouteProfiler
NewRouteProfiler creates a new performance profiler.
func (*RouteProfiler) GenerateReport ¶
func (rp *RouteProfiler) GenerateReport() *PerformanceReport
GenerateReport creates a comprehensive performance report.
func (*RouteProfiler) GetAllProfiles ¶
func (rp *RouteProfiler) GetAllProfiles() map[string]*RouteProfile
GetAllProfiles returns all route profiles.
func (*RouteProfiler) GetAnomalies ¶
func (rp *RouteProfiler) GetAnomalies() []PerformanceAnomaly
GetAnomalies returns detected performance anomalies.
func (*RouteProfiler) GetProfile ¶
func (rp *RouteProfiler) GetProfile(path, method string) *RouteProfile
GetProfile returns performance profile for a specific route.
func (*RouteProfiler) GetTopSlowest ¶
func (rp *RouteProfiler) GetTopSlowest(count int) []*RouteProfile
GetTopSlowest returns the slowest routes by P95 latency.
func (*RouteProfiler) ProfileMiddleware ¶
func (rp *RouteProfiler) ProfileMiddleware() gin.HandlerFunc
ProfileMiddleware creates Gin middleware for profiling.
func (*RouteProfiler) RecordDatabaseTime ¶
func (rp *RouteProfiler) RecordDatabaseTime(c *gin.Context, duration time.Duration)
RecordDatabaseTime records time spent in database operations.
func (*RouteProfiler) RecordExternalTime ¶
func (rp *RouteProfiler) RecordExternalTime(c *gin.Context, duration time.Duration)
RecordExternalTime records time spent in external API calls.
type RouteRequest ¶
type RouteRequest struct {
Method string
Path string
Handler string
StatusCode int
Duration time.Duration
UserAgent string
ClientIP string
}
RouteRequest represents a request to be recorded.
type RouteSpec ¶
type RouteSpec struct {
Prefix string `yaml:"prefix"`
Middleware []string `yaml:"middleware"`
Routes []RouteDefinition `yaml:"routes"`
RateLimit *RateLimitConfig `yaml:"rateLimit"`
}
RouteSpec defines the actual routes and their configuration.
type RouteStatistics ¶
type RouteStatistics struct {
Count int64 `json:"count"`
TotalDuration time.Duration `json:"total_duration"`
MinDuration time.Duration `json:"min_duration"`
MaxDuration time.Duration `json:"max_duration"`
AvgDuration time.Duration `json:"avg_duration"`
P50Duration time.Duration `json:"p50_duration"`
P95Duration time.Duration `json:"p95_duration"`
P99Duration time.Duration `json:"p99_duration"`
ErrorRate float64 `json:"error_rate"`
Throughput float64 `json:"throughput"`
AvgBytesIn int64 `json:"avg_bytes_in"`
AvgBytesOut int64 `json:"avg_bytes_out"`
}
RouteStatistics contains aggregated performance metrics.
type RouteStats ¶
type RouteStats struct {
Path string `json:"path"`
Method string `json:"method"`
Handler string `json:"handler"`
RequestCount int64 `json:"request_count"`
ErrorCount int64 `json:"error_count"`
TotalDuration time.Duration `json:"-"`
AverageDuration time.Duration `json:"average_duration"`
MinDuration time.Duration `json:"min_duration"`
MaxDuration time.Duration `json:"max_duration"`
LastAccessed time.Time `json:"last_accessed"`
StatusCodes map[int]int64 `json:"status_codes"`
}
RouteStats contains statistics for a specific route.
type RouteStore ¶
type RouteStore interface {
// CRUD Operations (kubectl-like API)
Apply(ctx context.Context, config *RouteConfig) error
Get(ctx context.Context, namespace, name string) (*RouteConfig, error)
List(ctx context.Context, namespace string) ([]*RouteConfig, error)
Delete(ctx context.Context, namespace, name string) error
// Watch for changes (k8s controller pattern)
Watch(ctx context.Context, namespace string) (<-chan RouteEvent, error)
// Lifecycle management
Start(ctx context.Context) error
Stop() error
}
Implementations can use files (docker-compose), etcd (k8s), or memory (testing).
type RouteTestCase ¶
type RouteTestCase struct {
Name string `yaml:"name"`
Input map[string]interface{} `yaml:"input"`
Headers map[string]string `yaml:"headers"`
Expect map[string]interface{} `yaml:"expect"`
StatusCode int `yaml:"statusCode"`
Description string `yaml:"description"`
}
RouteTestCase defines a test case for a route.
type RouteVersion ¶
type RouteVersion struct {
Version string `json:"version"`
Timestamp time.Time `json:"timestamp"`
Hash string `json:"hash"`
Author string `json:"author"`
Message string `json:"message"`
Routes map[string]*RouteConfig `json:"routes"`
Stats *VersionStats `json:"stats"`
ParentHash string `json:"parent_hash,omitempty"`
}
RouteVersion represents a version of route configuration.
type RouteVersionManager ¶
type RouteVersionManager struct {
// contains filtered or unexported fields
}
RouteVersionManager manages route configuration versions.
func NewRouteVersionManager ¶
func NewRouteVersionManager(storageDir string) *RouteVersionManager
NewRouteVersionManager creates a new version manager.
func (*RouteVersionManager) CreateVersion ¶
func (vm *RouteVersionManager) CreateVersion(routes map[string]*RouteConfig, message string) (*RouteVersion, error)
CreateVersion creates a new version from current routes.
func (*RouteVersionManager) DiffVersions ¶
func (vm *RouteVersionManager) DiffVersions(fromVersion, toVersion string) (*VersionDiff, error)
DiffVersions compares two versions.
func (*RouteVersionManager) GetVersion ¶
func (vm *RouteVersionManager) GetVersion(versionOrHash string) (*RouteVersion, error)
GetVersion retrieves a specific version.
func (*RouteVersionManager) ListVersions ¶
func (vm *RouteVersionManager) ListVersions() []*RouteVersion
ListVersions returns all versions sorted by timestamp.
func (*RouteVersionManager) Rollback ¶
func (vm *RouteVersionManager) Rollback(versionOrHash string) error
Rollback rolls back to a specific version.
func (*RouteVersionManager) SetAutoCommit ¶
func (vm *RouteVersionManager) SetAutoCommit(enabled bool)
AutoCommit enables or disables automatic version creation.
type SimpleRouteManager ¶
type SimpleRouteManager struct {
// contains filtered or unexported fields
}
SimpleRouteManager provides a simplified interface for using file-based routes.
func NewSimpleRouteManager ¶
func NewSimpleRouteManager(routesDir string, router *gin.Engine, registry *HandlerRegistry) *SimpleRouteManager
NewSimpleRouteManager creates a route manager that uses file-based storage.
func (*SimpleRouteManager) GetStore ¶
func (m *SimpleRouteManager) GetStore() RouteStore
GetStore returns the underlying route store for advanced operations.
func (*SimpleRouteManager) Start ¶
func (m *SimpleRouteManager) Start(ctx context.Context) error
Start initializes the route manager.
func (*SimpleRouteManager) Stop ¶
func (m *SimpleRouteManager) Stop() error
Stop shuts down the route manager.
type SystemStats ¶
type SystemStats struct {
TotalRequests int64 `json:"total_requests"`
TotalErrors int64 `json:"total_errors"`
ErrorRate float64 `json:"error_rate"`
Uptime time.Duration `json:"uptime"`
Routes []*RouteStats `json:"routes"`
RecentRequests []RequestLog `json:"recent_requests"`
}
SystemStats represents overall system statistics.
type VersionDiff ¶
type VersionDiff struct {
FromVersion string `json:"from_version"`
ToVersion string `json:"to_version"`
Added []string `json:"added"`
Modified []string `json:"modified"`
Deleted []string `json:"deleted"`
Changes map[string][]string `json:"changes"`
}
VersionDiff represents changes between versions.
type VersionStats ¶
type VersionStats struct {
TotalRoutes int `json:"total_routes"`
TotalEndpoints int `json:"total_endpoints"`
MethodBreakdown map[string]int `json:"method_breakdown"`
NamespaceCount map[string]int `json:"namespace_count"`
EnabledRoutes int `json:"enabled_routes"`
DisabledRoutes int `json:"disabled_routes"`
}
VersionStats contains statistics about a route version.