Versions in this module Expand all Collapse all v2 v2.5.0 Mar 9, 2026 Changes in this version + const EventTypeBackendAdded + const EventTypeBackendHealthy + const EventTypeBackendRemoved + const EventTypeBackendUnhealthy + const EventTypeCircuitBreakerClosed + const EventTypeCircuitBreakerHalfOpen + const EventTypeCircuitBreakerOpen + const EventTypeConfigLoaded + const EventTypeConfigValidated + const EventTypeDryRunComparison + const EventTypeError + const EventTypeLoadBalanceDecision + const EventTypeLoadBalanceRoundRobin + const EventTypeModuleStarted + const EventTypeModuleStopped + const EventTypeProxyCreated + const EventTypeProxyStarted + const EventTypeProxyStopped + const EventTypeRequestFailed + const EventTypeRequestProcessed + const EventTypeRequestProxied + const EventTypeRequestReceived + var ErrApplicationNil = errors.New("app cannot be nil") + var ErrBackendErrorStatus = errors.New("backend returned non-success status") + var ErrBackendIDRequired = errors.New("backend id required") + var ErrBackendNotConfigured = errors.New("backend not configured") + var ErrBackendNotFound = errors.New("backend not found") + var ErrBackendProxyNil = errors.New("backend proxy is nil") + var ErrBackendServiceNotFound = errors.New("backend service not found") + var ErrCannotRegisterRoutes = errors.New("cannot register routes: router is nil") + var ErrCircuitOpen = errors.New("circuit breaker is open") + var ErrConfigurationNil = errors.New("configuration is nil") + var ErrConfigurationNotLoaded = errors.New("configuration not loaded") + var ErrDefaultBackendNotDefined = errors.New("default backend is not defined in backend_services") + var ErrDryRunModeNotEnabled = errors.New("dry-run mode is not enabled") + var ErrEvaluatorFatal = errors.New("evaluator-fatal") + var ErrFeatureFlagNotFound = errors.New("feature flag not found") + var ErrInvalidDefaultFeatureFlagConfig = errors.New("invalid default configuration type for feature flags") + var ErrInvalidEmptyResponsePolicy = errors.New("invalid empty_policy: must be one of allow-empty, skip-empty, fail-on-empty") + var ErrInvalidFeatureFlagConfigType = errors.New("invalid feature flag configuration type") + var ErrLoggerNil = errors.New("logger cannot be nil") + var ErrMaxRetriesReached = errors.New("maximum number of retries reached") + var ErrNoAvailableBackend = errors.New("no available backend") + var ErrNoBackendsConfigured = errors.New("no backends configured") + var ErrNoDecision = errors.New("no-decision") + var ErrNoEvaluatorDecision = errors.New("no evaluator provided decision for flag") + var ErrNoEvaluatorsAvailable = errors.New("no feature flag evaluators available") + var ErrNoFeatureFlagConfigProvider = errors.New("no configuration provider available for feature flags") + var ErrNoHostname = errors.New("no hostname in URL") + var ErrNoSubjectForEventEmission = errors.New("no subject available for event emission") + var ErrRequestTimeout = errors.New("request timed out") + var ErrServiceNotHandleFunc = errors.New("service does not implement HandleFunc interface") + var ErrServiceURLRequired = errors.New("service URL required") + var ErrTenantAwareConfigCreation = errors.New("failed to create tenant-aware config for feature flags") + var ErrTenantIDRequired = errors.New("tenant ID is required but TenantIDHeader is not set") + var ErrUnexpectedConfigType = errors.New("unexpected config type") + var ErrUnexpectedStatusCode = errors.New("unexpected status code") + func MakeJSONResponse(statusCode int, data interface{}) (*http.Response, error) + func ProvideConfig() interface + func RetryWithPolicy(ctx context.Context, policy RetryPolicy, fn RetryFunc, ...) (interface{}, int, error) + func TenantIDFromRequest(tenantHeader string, r *http.Request) (string, bool) + type Backend struct + Client *http.Client + ID string + URL string + type BackendCircuitBreakerConfig struct + Enabled bool + FailureThreshold int + RecoveryTimeout time.Duration + type BackendEndpointRequest struct + Backend string + Headers map[string]string + Method string + Path string + QueryParams map[string]string + type BackendHealthCheckConfig struct + Enabled bool + ExpectedStatusCodes []int + Interval time.Duration + Timeout time.Duration + type BackendHealthConfig struct + Enabled bool + Endpoint string + ExpectedStatusCodes []int + Interval time.Duration + Timeout time.Duration + type BackendServiceConfig struct + AlternativeBackend string + AlternativeBackends []string + CircuitBreaker BackendCircuitBreakerConfig + ConnectionTimeout time.Duration + CustomHostname string + Endpoints map[string]EndpointConfig + FeatureFlag string + FeatureFlagID string + HeaderRewriting HeaderRewritingConfig + HealthCheck BackendHealthCheckConfig + HealthEndpoint string + HostnameHandling string + IdleTimeout time.Duration + MaxConnections int + MaxRetries int + PathRewrite string + PathRewriting PathRewritingConfig + QueueSize int + QueueTimeout time.Duration + ResponseHeaderRewriting ResponseHeaderRewritingConfig + RetryDelay time.Duration + URL string + type CachedResponse struct + Body []byte + ExpirationTime time.Time + Headers http.Header + LastAccessed time.Time + StatusCode int + type CircuitBreaker struct + func NewCircuitBreaker(backendName string, metricsCollector *MetricsCollector) *CircuitBreaker + func NewCircuitBreakerWithConfig(backendName string, config CircuitBreakerConfig, ...) *CircuitBreaker + func (cb *CircuitBreaker) Execute(req *http.Request, fn func(*http.Request) (*http.Response, error)) (*http.Response, error) + func (cb *CircuitBreaker) GetFailureCount() int + func (cb *CircuitBreaker) GetState() CircuitState + func (cb *CircuitBreaker) IsOpen() bool + func (cb *CircuitBreaker) RecordFailure() + func (cb *CircuitBreaker) RecordSuccess() + func (cb *CircuitBreaker) Reset() + func (cb *CircuitBreaker) WithFailureThreshold(threshold int) *CircuitBreaker + func (cb *CircuitBreaker) WithMetricsCollector(collector *MetricsCollector) *CircuitBreaker + func (cb *CircuitBreaker) WithRequestTimeout(timeout time.Duration) *CircuitBreaker + func (cb *CircuitBreaker) WithResetTimeout(timeout time.Duration) *CircuitBreaker + type CircuitBreakerConfig struct + Enabled bool + FailureThreshold int + HalfOpenAllowedRequests int + OpenTimeout time.Duration + RequestTimeout time.Duration + SuccessRateThreshold float64 + SuccessThreshold int + WindowSize int + type CircuitBreakerInfo struct + FailureCount int + FailureThreshold int + Failures int + LastAttempt time.Time + LastFailure time.Time + ResetTimeout string + State string + SuccessCount int + type CircuitBreakerProvider func(backendID string) *HealthCircuitBreakerInfo + type CircuitState int + const DefaultRequestTimeout + const StateClosed + const StateHalfOpen + const StateOpen + func (s CircuitState) String() string + type ComparisonResult struct + BodyMatch bool + Differences []string + HeaderDiffs map[string]HeaderDiff + HeadersMatch bool + StatusCodeMatch bool + type CompositeHandler struct + func NewCompositeHandler(backends []*Backend, strategy CompositeStrategy, responseTimeout time.Duration) *CompositeHandler + func (h *CompositeHandler) ConfigureCircuitBreakers(globalConfig CircuitBreakerConfig, ...) + func (h *CompositeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) + func (h *CompositeHandler) SetEmptyResponsePolicy(policy EmptyResponsePolicy) + func (h *CompositeHandler) SetEventEmitter(emitter func(eventType string, data map[string]interface{})) + func (h *CompositeHandler) SetFanOutMerger(merger FanOutMerger) + func (h *CompositeHandler) SetPipelineConfig(config *PipelineConfig) + func (h *CompositeHandler) SetResponseCache(cache *responseCache) + func (h *CompositeHandler) SetResponseTransformer(transformer ResponseTransformer) + type CompositeResponse struct + Body []byte + Headers http.Header + StatusCode int + type CompositeRoute struct + AlternativeBackend string + Backends []string + EmptyPolicy string + FeatureFlagID string + Pattern string + Strategy string + type CompositeStrategy string + const StrategyFanOutMerge + const StrategyFirstSuccess + const StrategyMerge + const StrategyPipeline + const StrategySequential + type DebugConfig struct + BackendsEndpoint string + CircuitBreakersEndpoint string + Enabled bool + FlagsEndpoint string + HealthChecksEndpoint string + InfoEndpoint string + type DebugEndpointsConfig struct + AuthToken string + BasePath string + Enabled bool + RequireAuth bool + type DebugHandler struct + func NewDebugHandler(config DebugEndpointsConfig, featureFlagEval FeatureFlagEvaluator, ...) *DebugHandler + func (d *DebugHandler) HandleBackends(w http.ResponseWriter, r *http.Request) + func (d *DebugHandler) HandleCircuitBreakers(w http.ResponseWriter, r *http.Request) + func (d *DebugHandler) HandleFlags(w http.ResponseWriter, r *http.Request) + func (d *DebugHandler) HandleHealthChecks(w http.ResponseWriter, r *http.Request) + func (d *DebugHandler) HandleInfo(w http.ResponseWriter, r *http.Request) + func (d *DebugHandler) RegisterRoutes(mux *http.ServeMux) + func (d *DebugHandler) SetCircuitBreakers(circuitBreakers map[string]*CircuitBreaker) + func (d *DebugHandler) SetHealthCheckers(healthCheckers map[string]*HealthChecker) + type DebugInfo struct + BackendServices map[string]string + CircuitBreakers map[string]CircuitBreakerInfo + Environment string + Flags map[string]interface{} + HealthChecks map[string]HealthInfo + ModuleName string + Routes map[string]string + Tenant string + Timestamp time.Time + type DryRunConfig struct + CompareHeaders []string + DefaultResponseBackend string + Enabled bool + IgnoreHeaders []string + LogResponses bool + MaxResponseSize int64 + type DryRunHandler struct + func NewDryRunHandler(config DryRunConfig, tenantIDHeader string, logger modular.Logger) *DryRunHandler + func (d *DryRunHandler) ProcessDryRun(ctx context.Context, req *http.Request, ...) (*DryRunResult, error) + type DryRunResult struct + Comparison ComparisonResult + Duration DurationInfo + Endpoint string + Method string + PrimaryBackend string + PrimaryResponse ResponseInfo + RequestID string + ReturnedResponse string + SecondaryBackend string + SecondaryResponse ResponseInfo + TenantID string + Timestamp time.Time + func (d *DryRunResult) GetReturnedResponse() ResponseInfo + type DurationInfo struct + Primary time.Duration + Secondary time.Duration + Total time.Duration + type EmptyResponsePolicy string + const EmptyResponseAllow + const EmptyResponseFail + const EmptyResponseSkip + type EndpointConfig struct + AlternativeBackend string + FeatureFlagID string + HeaderRewriting HeaderRewritingConfig + PathRewriting PathRewritingConfig + Pattern string + ResponseHeaderRewriting ResponseHeaderRewritingConfig + type EndpointMapping struct + Endpoints []BackendEndpointRequest + ResponseTransformer func(ctx context.Context, req *http.Request, responses map[string]*http.Response) (*CompositeResponse, error) + type EndpointRewriteRule struct + Backend string + Pattern string + Replacement string + StripQueryParams bool + type ErrorHandlingConfig struct + ConnectionRetries int + EnableCustomPages bool + RetryAttempts int + RetryDelay time.Duration + type FanOutMerger func(ctx context.Context, originalReq *http.Request, responses map[string][]byte) (*http.Response, error) + type FeatureFlagAggregator struct + func NewFeatureFlagAggregator(app modular.Application, logger *slog.Logger) *FeatureFlagAggregator + func (a *FeatureFlagAggregator) EvaluateFlag(ctx context.Context, flagID string, tenantID modular.TenantID, ...) (bool, error) + func (a *FeatureFlagAggregator) EvaluateFlagWithDefault(ctx context.Context, flagID string, tenantID modular.TenantID, ...) bool + type FeatureFlagEvaluator interface + EvaluateFlag func(ctx context.Context, flagID string, tenantID modular.TenantID, ...) (bool, error) + EvaluateFlagWithDefault func(ctx context.Context, flagID string, tenantID modular.TenantID, ...) bool + type FeatureFlagsConfig struct + Enabled bool + Flags map[string]bool + type FileBasedFeatureFlagEvaluator struct + func NewFileBasedFeatureFlagEvaluator(ctx context.Context, app modular.Application, logger *slog.Logger) (*FileBasedFeatureFlagEvaluator, error) + func (f *FileBasedFeatureFlagEvaluator) EvaluateFlag(ctx context.Context, flagID string, tenantID modular.TenantID, ...) (bool, error) + func (f *FileBasedFeatureFlagEvaluator) EvaluateFlagWithDefault(ctx context.Context, flagID string, tenantID modular.TenantID, ...) bool + type HeaderConfig struct + RemoveHeaders []string + SetHeaders map[string]string + type HeaderDiff struct + Primary string + Secondary string + type HeaderRewritingConfig struct + CustomHostname string + HostnameHandling HostnameHandlingMode + RemoveHeaders []string + SetHeaders map[string]string + type HealthCheckConfig struct + BackendHealthCheckConfig map[string]BackendHealthConfig + Enabled bool + ExpectedStatusCodes []int + HealthEndpoints map[string]string + Interval time.Duration + RecentRequestThreshold time.Duration + Timeout time.Duration + type HealthChecker struct + func NewHealthChecker(config *HealthCheckConfig, backends map[string]string, httpClient *http.Client, ...) *HealthChecker + func (hc *HealthChecker) GetBackendHealthStatus(backendID string) (*HealthStatus, bool) + func (hc *HealthChecker) GetHealthStatus() map[string]*HealthStatus + func (hc *HealthChecker) GetOverallHealthStatus(includeDetails bool) *OverallHealthStatus + func (hc *HealthChecker) IsRunning() bool + func (hc *HealthChecker) RecordBackendRequest(backendID string) + func (hc *HealthChecker) SetCircuitBreakerProvider(provider CircuitBreakerProvider) + func (hc *HealthChecker) SetEventEmitter(emitter HealthEventEmitter) + func (hc *HealthChecker) Start(ctx context.Context) error + func (hc *HealthChecker) Stop(ctx context.Context) + func (hc *HealthChecker) UpdateBackends(ctx context.Context, backends map[string]string) + func (hc *HealthChecker) UpdateHealthConfig(ctx context.Context, cfg *HealthCheckConfig) + type HealthCircuitBreakerInfo struct + FailureCount int + IsOpen bool + State string + type HealthEventEmitter func(eventType string, data map[string]interface{}) + type HealthInfo struct + ChecksSkipped int64 + CircuitBreakerOpen bool + CircuitBreakerState string + CircuitFailureCount int + DNSResolved bool + HealthCheckPassing bool + LastCheck time.Time + LastError string + LastSuccess time.Time + ResolvedIPs []string + ResponseTime string + Status string + StatusCode int + SuccessfulChecks int64 + TotalChecks int64 + type HealthStatus struct + BackendID string + ChecksSkipped int64 + CircuitBreakerOpen bool + CircuitBreakerState string + CircuitFailureCount int + DNSResolved bool + HealthCheckPassing bool + Healthy bool + LastCheck time.Time + LastError string + LastRequest time.Time + LastSuccess time.Time + ResolvedIPs []string + ResponseTime time.Duration + SuccessfulChecks int64 + TotalChecks int64 + URL string + type HostnameHandlingMode string + const HostnamePreserveOriginal + const HostnameUseBackend + const HostnameUseCustom + type MetricsCollector struct + func NewMetricsCollector() *MetricsCollector + func (m *MetricsCollector) GetMetrics() map[string]interface{} + func (m *MetricsCollector) MetricsHandler() http.HandlerFunc + func (m *MetricsCollector) RecordRequest(backend string, start time.Time, statusCode int, err error, ...) + func (m *MetricsCollector) SetCircuitBreakerStateString(backend string, state string) + func (m *MetricsCollector) SetCircuitBreakerStatus(backend string, isOpen bool) + type MetricsConfig struct + Enabled bool + Endpoint string + type OverallHealthStatus struct + BackendDetails map[string]*HealthStatus + CircuitOpenCount int + Healthy bool + HealthyBackends int + LastCheck time.Time + TotalBackends int + UnhealthyBackends int + type PathMatcher struct + func NewPathMatcher() *PathMatcher + func (pm *PathMatcher) AddRoutePattern(backendID, pattern string) + func (pm *PathMatcher) MatchBackend(path string) string + type PathRewritingConfig struct + BasePathRewrite string + EndpointRewrites map[string]EndpointRewriteRule + StripBasePath string + type PipelineConfig struct + RequestBuilder PipelineRequestBuilder + ResponseMerger PipelineResponseMerger + type PipelineRequestBuilder func(ctx context.Context, originalReq *http.Request, ...) (*http.Request, error) + type PipelineResponseMerger func(ctx context.Context, originalReq *http.Request, allResponses map[string][]byte) (*http.Response, error) + type ResponseHeaderRewritingConfig struct + RemoveHeaders []string + SetHeaders map[string]string + type ResponseInfo struct + Body string + BodySize int64 + Error string + Headers map[string]string + ResponseTime time.Duration + StatusCode int + type ResponseTransformer func(responses map[string]*http.Response) (*http.Response, error) + type RetryFunc func(ctx context.Context) (interface{}, int, error) + type RetryPolicy struct + BaseDelay time.Duration + Jitter float64 + MaxDelay time.Duration + MaxRetries int + RetryableStatusCodes map[int]bool + Timeout time.Duration + func DefaultRetryPolicy() RetryPolicy + func (p RetryPolicy) CalculateBackoff(attempt int) time.Duration + func (p RetryPolicy) ShouldRetry(statusCode int) bool + func (p RetryPolicy) WithBaseDelay(baseDelay time.Duration) RetryPolicy + func (p RetryPolicy) WithJitter(jitter float64) RetryPolicy + func (p RetryPolicy) WithMaxDelay(maxDelay time.Duration) RetryPolicy + func (p RetryPolicy) WithMaxRetries(maxRetries int) RetryPolicy + func (p RetryPolicy) WithRetryableStatusCodes(codes ...int) RetryPolicy + func (p RetryPolicy) WithTimeout(timeout time.Duration) RetryPolicy + type ReverseProxyConfig struct + BackendCircuitBreakers map[string]CircuitBreakerConfig + BackendConfigs map[string]BackendServiceConfig + BackendServices map[string]string + CacheEnabled bool + CacheTTL time.Duration + CircuitBreakerConfig CircuitBreakerConfig + CompositeRoutes map[string]CompositeRoute + DebugConfig DebugConfig + DebugEndpoints DebugEndpointsConfig + DefaultBackend string + DryRun DryRunConfig + DryRunConfig DryRunConfig + ErrorHandling ErrorHandlingConfig + FeatureFlags FeatureFlagsConfig + GlobalTimeout time.Duration + HeaderConfig HeaderConfig + HealthCheck HealthCheckConfig + MetricsConfig MetricsConfig + MetricsEnabled bool + MetricsEndpoint string + MetricsPath string + RequestTimeout time.Duration + RequireTenantID bool + ResponseHeaderConfig ResponseHeaderRewritingConfig + RouteConfigs map[string]RouteConfig + Routes map[string]string + TenantIDHeader string + type ReverseProxyModule struct + func NewModule() *ReverseProxyModule + func (m *ReverseProxyModule) AddBackend(backendID, serviceURL string) error + func (m *ReverseProxyModule) AddBackendRoute(backendID, routePattern string) error + func (m *ReverseProxyModule) AddCompositeRoute(pattern string, backends []string, strategy string) + func (m *ReverseProxyModule) Constructor() modular.ModuleConstructor + func (m *ReverseProxyModule) EmitEvent(ctx context.Context, event cloudevents.Event) error + func (m *ReverseProxyModule) GetBackendHealthStatus(backendID string) (*HealthStatus, bool) + func (m *ReverseProxyModule) GetConfig() *ReverseProxyConfig + func (m *ReverseProxyModule) GetHealthStatus() map[string]*HealthStatus + func (m *ReverseProxyModule) GetOverallHealthStatus(includeDetails bool) *OverallHealthStatus + func (m *ReverseProxyModule) GetRegisteredEventTypes() []string + func (m *ReverseProxyModule) Init(app modular.Application) error + func (m *ReverseProxyModule) IsHealthCheckEnabled() bool + func (m *ReverseProxyModule) Name() string + func (m *ReverseProxyModule) OnTenantRegistered(tenantID modular.TenantID) + func (m *ReverseProxyModule) OnTenantRemoved(tenantID modular.TenantID) + func (m *ReverseProxyModule) ProvidesServices() []modular.ServiceProvider + func (m *ReverseProxyModule) RegisterConfig(app modular.Application) error + func (m *ReverseProxyModule) RegisterCustomEndpoint(pattern string, mapping EndpointMapping) + func (m *ReverseProxyModule) RegisterObservers(subject modular.Subject) error + func (m *ReverseProxyModule) RemoveBackend(backendID string) error + func (m *ReverseProxyModule) RequiresServices() []modular.ServiceDependency + func (m *ReverseProxyModule) SetEmptyResponsePolicy(pattern string, policy EmptyResponsePolicy) + func (m *ReverseProxyModule) SetFanOutMerger(pattern string, merger FanOutMerger) + func (m *ReverseProxyModule) SetHttpClient(client *http.Client) + func (m *ReverseProxyModule) SetPipelineConfig(pattern string, config PipelineConfig) + func (m *ReverseProxyModule) SetResponseHeaderModifier(modifier func(*http.Response, string, modular.TenantID) error) + func (m *ReverseProxyModule) SetResponseTransformer(pattern string, transformer ResponseTransformer) + func (m *ReverseProxyModule) Start(ctx context.Context) error + func (m *ReverseProxyModule) Stop(ctx context.Context) error + type RouteConfig struct + AlternativeBackend string + AlternativeBackends []string + CompositeBackends []string + DryRun bool + DryRunBackend string + FeatureFlag string + FeatureFlagID string + PathRewrite string + Timeout time.Duration + type WeightedEvaluator interface + Weight func() int Other modules containing this package github.com/GoCodeAlone/modular/modules/reverseproxy