Documentation
¶
Overview ¶
Package core provides a base module implementation for easy module development.
Package core provides a feature flag system for modular feature control.
Package core provides license management for module activation.
Package core provides the foundational module system for AegisGate. It defines the Module interface, module registry, and license management for the modular plugin architecture.
Package core provides the module registry for managing all AegisGate modules.
Package core provides tier and feature management for AegisGate. This file defines the 4-tier system: Community -> Developer -> Professional -> Enterprise
Index ¶
- Variables
- func GenerateLicense(licenseType LicenseType, email string, modules []string, tiers []Tier, ...) (string, error)
- func GetCommunityFeatures() []string
- func GetDeveloperFeatures() []string
- func GetEnterpriseFeatures() []string
- func GetFeaturesByTier(tier Tier) []string
- func GetProfessionalFeatures() []string
- type BaseModule
- func (m *BaseModule) Dependencies() []string
- func (m *BaseModule) GetConfig() ModuleConfig
- func (m *BaseModule) GetRegistry() *Registry
- func (m *BaseModule) Health(ctx context.Context) HealthStatus
- func (m *BaseModule) Initialize(ctx context.Context, config ModuleConfig) error
- func (m *BaseModule) Lifecycle() *ModuleLifecycle
- func (m *BaseModule) Metadata() ModuleMetadata
- func (m *BaseModule) OptionalDependencies() []string
- func (m *BaseModule) Provides() []string
- func (m *BaseModule) SetAfterStart(fn func(ctx context.Context) error)
- func (m *BaseModule) SetAfterStop(fn func(ctx context.Context) error)
- func (m *BaseModule) SetBeforeStart(fn func(ctx context.Context) error)
- func (m *BaseModule) SetBeforeStop(fn func(ctx context.Context) error)
- func (m *BaseModule) SetOnError(fn func(ctx context.Context, err error))
- func (m *BaseModule) SetRegistry(registry *Registry)
- func (m *BaseModule) SetStatus(status ModuleStatus)
- func (m *BaseModule) Start(ctx context.Context) error
- func (m *BaseModule) Status() ModuleStatus
- func (m *BaseModule) Stop(ctx context.Context) error
- type Capability
- type ErrFeatureAlreadyExists
- type ErrFeatureNotFound
- type FeatureFlag
- type FeatureRegistry
- func (fr *FeatureRegistry) Disable(id string) error
- func (fr *FeatureRegistry) DisableAllForModule(moduleID string)
- func (fr *FeatureRegistry) Enable(id string) error
- func (fr *FeatureRegistry) EnableAllForModule(moduleID string)
- func (fr *FeatureRegistry) Get(id string) (*FeatureFlag, bool)
- func (fr *FeatureRegistry) IsEnabled(id string) bool
- func (fr *FeatureRegistry) List() []*FeatureFlag
- func (fr *FeatureRegistry) ListByModule(moduleID string) []*FeatureFlag
- func (fr *FeatureRegistry) Register(flag FeatureFlag) error
- func (fr *FeatureRegistry) Unregister(id string)
- type HealthStatus
- type License
- type LicenseConfig
- type LicenseManager
- func (lm *LicenseManager) ClearOverrides()
- func (lm *LicenseManager) GetLicense() *License
- func (lm *LicenseManager) GetStatus() LicenseStatus
- func (lm *LicenseManager) IsFeatureLicensed(feature string) bool
- func (lm *LicenseManager) IsModuleLicensed(moduleID string, tier Tier) bool
- func (lm *LicenseManager) LicenseExpiringSoon(within time.Duration) bool
- func (lm *LicenseManager) SetLicenseKey(key string) error
- func (lm *LicenseManager) SetModuleOverride(moduleID string, allowed bool)
- func (lm *LicenseManager) SetPublicKey(pemData []byte) error
- func (lm *LicenseManager) Summary() *LicenseSummary
- type LicenseStatus
- type LicenseSummary
- type LicenseType
- type Module
- type ModuleCategory
- type ModuleConfig
- type ModuleLifecycle
- type ModuleMetadata
- type ModuleStatus
- type ModuleWithConfig
- type ModuleWithLifecycle
- type ModuleWithMetrics
- type ModuleWithRoutes
- type Registry
- func (r *Registry) Disable(ctx context.Context, id string) error
- func (r *Registry) Enable(ctx context.Context, id string) error
- func (r *Registry) Get(id string) (Module, bool)
- func (r *Registry) GetCapability(capID string) (*Capability, bool)
- func (r *Registry) GetConfig(id string) (ModuleConfig, bool)
- func (r *Registry) GetStatus(id string) ModuleStatus
- func (r *Registry) HasCapability(capID string) bool
- func (r *Registry) Health(ctx context.Context) map[string]HealthStatus
- func (r *Registry) Initialize(ctx context.Context) error
- func (r *Registry) List() []string
- func (r *Registry) ListByCategory(category ModuleCategory) []string
- func (r *Registry) ListByTier(tier Tier) []string
- func (r *Registry) Register(module Module) error
- func (r *Registry) SetConfig(id string, config ModuleConfig) error
- func (r *Registry) Start(ctx context.Context) error
- func (r *Registry) Stop(ctx context.Context) error
- func (r *Registry) Unregister(id string) error
- func (r *Registry) Uptime() time.Duration
- type RegistryConfig
- type Tier
- func (t Tier) CanAccess(requiredTier Tier) bool
- func (t Tier) GetPriceInfo() (monthly float64, annual float64, perUser bool)
- func (t Tier) GetTierLimits() TierLimits
- func (t Tier) GetUpgradePath() Tier
- func (t Tier) IsValid() bool
- func (t Tier) MarshalJSON() ([]byte, error)
- func (t Tier) String() string
- func (t *Tier) UnmarshalJSON(data []byte) error
- type TierLimits
Constants ¶
This section is empty.
Variables ¶
var FeatureTierMapping = map[string]Tier{}/* 124 elements not displayed */
var Now = func() time.Time { return time.Now() }
Now is a variable for testing purposes.
Functions ¶
func GenerateLicense ¶
func GenerateLicense(licenseType LicenseType, email string, modules []string, tiers []Tier, validFor time.Duration) (string, error)
GenerateLicense generates a new license (for testing/admin purpose).
func GetCommunityFeatures ¶
func GetCommunityFeatures() []string
GetCommunityFeatures returns all community-available features
func GetDeveloperFeatures ¶
func GetDeveloperFeatures() []string
GetDeveloperFeatures returns all developer-available features
func GetEnterpriseFeatures ¶
func GetEnterpriseFeatures() []string
GetEnterpriseFeatures returns all enterprise-available features
func GetFeaturesByTier ¶
GetFeaturesByTier returns all features available to a tier
func GetProfessionalFeatures ¶
func GetProfessionalFeatures() []string
GetProfessionalFeatures returns all professional-available features
Types ¶
type BaseModule ¶
type BaseModule struct {
// contains filtered or unexported fields
}
BaseModule provides a default implementation of the Module interface. Modules can embed this struct to avoid implementing all methods.
func NewBaseModule ¶
func NewBaseModule(meta ModuleMetadata) *BaseModule
NewBaseModule creates a new base module with the given metadata.
func (*BaseModule) Dependencies ¶
func (m *BaseModule) Dependencies() []string
Dependencies returns the IDs of modules this module depends on.
func (*BaseModule) GetConfig ¶
func (m *BaseModule) GetConfig() ModuleConfig
GetConfig returns the current module configuration.
func (*BaseModule) GetRegistry ¶
func (m *BaseModule) GetRegistry() *Registry
GetRegistry returns the module registry.
func (*BaseModule) Health ¶
func (m *BaseModule) Health(ctx context.Context) HealthStatus
Health returns the module's health status.
func (*BaseModule) Initialize ¶
func (m *BaseModule) Initialize(ctx context.Context, config ModuleConfig) error
Initialize prepares the module for operation.
func (*BaseModule) Lifecycle ¶
func (m *BaseModule) Lifecycle() *ModuleLifecycle
Lifecycle returns the module lifecycle hooks.
func (*BaseModule) Metadata ¶
func (m *BaseModule) Metadata() ModuleMetadata
Metadata returns the module's metadata.
func (*BaseModule) OptionalDependencies ¶
func (m *BaseModule) OptionalDependencies() []string
OptionalDependencies returns IDs of modules that enhance functionality.
func (*BaseModule) Provides ¶
func (m *BaseModule) Provides() []string
Provides returns what capabilities this module provides.
func (*BaseModule) SetAfterStart ¶
func (m *BaseModule) SetAfterStart(fn func(ctx context.Context) error)
SetAfterStart sets the after-start lifecycle hook.
func (*BaseModule) SetAfterStop ¶
func (m *BaseModule) SetAfterStop(fn func(ctx context.Context) error)
SetAfterStop sets the after-stop lifecycle hook.
func (*BaseModule) SetBeforeStart ¶
func (m *BaseModule) SetBeforeStart(fn func(ctx context.Context) error)
SetBeforeStart sets the before-start lifecycle hook.
func (*BaseModule) SetBeforeStop ¶
func (m *BaseModule) SetBeforeStop(fn func(ctx context.Context) error)
SetBeforeStop sets the before-stop lifecycle hook.
func (*BaseModule) SetOnError ¶
func (m *BaseModule) SetOnError(fn func(ctx context.Context, err error))
SetOnError sets the error handler hook.
func (*BaseModule) SetRegistry ¶
func (m *BaseModule) SetRegistry(registry *Registry)
SetRegistry allows the module to access other modules.
func (*BaseModule) SetStatus ¶
func (m *BaseModule) SetStatus(status ModuleStatus)
SetStatus updates the module status.
func (*BaseModule) Start ¶
func (m *BaseModule) Start(ctx context.Context) error
Start begins the module's operation.
func (*BaseModule) Status ¶
func (m *BaseModule) Status() ModuleStatus
Status returns the current operational status.
type Capability ¶
type Capability struct {
ID string
Name string
Description string
ProviderID string // Module ID that provides this capability
Version string
}
Capability represents a named capability provided by modules.
type ErrFeatureAlreadyExists ¶
type ErrFeatureAlreadyExists struct {
ID string
}
Error types
func (ErrFeatureAlreadyExists) Error ¶
func (e ErrFeatureAlreadyExists) Error() string
type ErrFeatureNotFound ¶
type ErrFeatureNotFound struct {
ID string
}
func (ErrFeatureNotFound) Error ¶
func (e ErrFeatureNotFound) Error() string
type FeatureFlag ¶
type FeatureFlag struct {
ID string
Name string
Description string
ModuleID string // Owner module
Enabled bool
Requires []string // Other feature IDs that must be enabled
}
FeatureFlag represents a feature that can be enabled or disabled.
type FeatureRegistry ¶
type FeatureRegistry struct {
// contains filtered or unexported fields
}
FeatureRegistry manages feature flags across all modules.
func NewFeatureRegistry ¶
func NewFeatureRegistry(registry *Registry) *FeatureRegistry
NewFeatureRegistry creates a new feature registry.
func (*FeatureRegistry) Disable ¶
func (fr *FeatureRegistry) Disable(id string) error
Disable disables a feature flag.
func (*FeatureRegistry) DisableAllForModule ¶
func (fr *FeatureRegistry) DisableAllForModule(moduleID string)
DisableAllForModule disables all features for a module.
func (*FeatureRegistry) Enable ¶
func (fr *FeatureRegistry) Enable(id string) error
Enable enables a feature flag.
func (*FeatureRegistry) EnableAllForModule ¶
func (fr *FeatureRegistry) EnableAllForModule(moduleID string)
EnableAllForModule enables all features for a module.
func (*FeatureRegistry) Get ¶
func (fr *FeatureRegistry) Get(id string) (*FeatureFlag, bool)
Get returns a feature flag by ID.
func (*FeatureRegistry) IsEnabled ¶
func (fr *FeatureRegistry) IsEnabled(id string) bool
IsEnabled checks if a feature is enabled.
func (*FeatureRegistry) List ¶
func (fr *FeatureRegistry) List() []*FeatureFlag
List returns all registered feature flags.
func (*FeatureRegistry) ListByModule ¶
func (fr *FeatureRegistry) ListByModule(moduleID string) []*FeatureFlag
ListByModule returns feature flags for a specific module.
func (*FeatureRegistry) Register ¶
func (fr *FeatureRegistry) Register(flag FeatureFlag) error
Register registers a new feature flag.
func (*FeatureRegistry) Unregister ¶
func (fr *FeatureRegistry) Unregister(id string)
Unregister removes a feature flag.
type HealthStatus ¶
type HealthStatus struct {
Healthy bool `json:"healthy"`
Message string `json:"message,omitempty"`
LastCheck time.Time `json:"last_check"`
Metrics map[string]interface{} `json:"metrics,omitempty"`
}
HealthStatus represents the health check result of a module.
type License ¶
type License struct {
ID string `json:"id"`
Type LicenseType `json:"type"`
Email string `json:"email"`
Organization string `json:"organization,omitempty"`
Modules []string `json:"modules,omitempty"`
Tiers []Tier `json:"tiers,omitempty"`
IssuedAt time.Time `json:"issued_at"`
ExpiresAt time.Time `json:"expires_at"`
MaxServers int `json:"max_servers,omitempty"`
Features []string `json:"features,omitempty"`
Signature string `json:"signature,omitempty"`
}
License represents a parsed license.
type LicenseConfig ¶
type LicenseConfig struct {
LicenseKey string
PublicKeyPEM string // For production: embedded public key
GracePeriod time.Duration
}
LicenseConfig contains configuration for the license manager.
type LicenseManager ¶
type LicenseManager struct {
// contains filtered or unexported fields
}
LicenseManager handles license validation and module activation.
func NewLicenseManager ¶
func NewLicenseManager(licenseKey string) *LicenseManager
NewLicenseManager creates a new license manager.
func (*LicenseManager) ClearOverrides ¶
func (lm *LicenseManager) ClearOverrides()
ClearOverrides removes all development overrides.
func (*LicenseManager) GetLicense ¶
func (lm *LicenseManager) GetLicense() *License
GetLicense returns the current license.
func (*LicenseManager) GetStatus ¶
func (lm *LicenseManager) GetStatus() LicenseStatus
GetStatus returns the current license status.
func (*LicenseManager) IsFeatureLicensed ¶
func (lm *LicenseManager) IsFeatureLicensed(feature string) bool
IsFeatureLicensed checks if a specific feature is licensed.
func (*LicenseManager) IsModuleLicensed ¶
func (lm *LicenseManager) IsModuleLicensed(moduleID string, tier Tier) bool
IsModuleLicensed checks if a specific module is licensed.
func (*LicenseManager) LicenseExpiringSoon ¶
func (lm *LicenseManager) LicenseExpiringSoon(within time.Duration) bool
LicenseExpiringSoon checks if license expires within the given duration.
func (*LicenseManager) SetLicenseKey ¶
func (lm *LicenseManager) SetLicenseKey(key string) error
SetLicenseKey sets or updates the license key.
func (*LicenseManager) SetModuleOverride ¶
func (lm *LicenseManager) SetModuleOverride(moduleID string, allowed bool)
SetModuleOverride sets a development/testing override for a module.
func (*LicenseManager) SetPublicKey ¶
func (lm *LicenseManager) SetPublicKey(pemData []byte) error
SetPublicKey sets the public key for license signature verification.
func (*LicenseManager) Summary ¶
func (lm *LicenseManager) Summary() *LicenseSummary
Summary returns a human-readable license summary.
type LicenseStatus ¶
type LicenseStatus int
LicenseStatus represents the validity of a license.
const ( LicenseStatusValid LicenseStatus = iota LicenseStatusExpired LicenseStatusInvalid LicenseStatusNotFound LicenseStatusTierMismatch )
func (LicenseStatus) String ¶
func (s LicenseStatus) String() string
type LicenseSummary ¶
type LicenseSummary struct {
Type string `json:"type"`
Email string `json:"email"`
Organization string `json:"organization,omitempty"`
Modules []string `json:"modules"`
MaxTier string `json:"max_tier"`
IssuedAt time.Time `json:"issued_at"`
ExpiresAt time.Time `json:"expires_at"`
DaysRemaining int `json:"days_remaining"`
Status string `json:"status"`
}
LicenseSummary provides a human-readable license summary.
type LicenseType ¶
type LicenseType string
LicenseType represents the type of license.
const ( LicenseTypeCommunity LicenseType = "community" LicenseTypeProfessional LicenseType = "professional" LicenseTypeEnterprise LicenseType = "enterprise" LicenseTypeEnterpriseAI LicenseType = "enterprise-ai" LicenseTypeCustom LicenseType = "custom" )
type Module ¶
type Module interface {
// Metadata returns the module's descriptive information.
Metadata() ModuleMetadata
// Initialize prepares the module for operation.
// Called once during application startup.
Initialize(ctx context.Context, config ModuleConfig) error
// Start begins the module's operation.
// Called after all dependencies are initialized.
Start(ctx context.Context) error
// Stop gracefully shuts down the module.
Stop(ctx context.Context) error
// Status returns the current operational status.
Status() ModuleStatus
// Health returns the module's health status.
Health(ctx context.Context) HealthStatus
// Dependencies returns the IDs of modules this module depends on.
Dependencies() []string
// OptionalDependencies returns IDs of modules that enhance functionality.
OptionalDependencies() []string
// Provides returns what capabilities this module provides.
Provides() []string
// SetRegistry allows the module to access other modules.
SetRegistry(registry *Registry)
}
Module defines the interface that all AegisGate modules must implement.
type ModuleCategory ¶
type ModuleCategory string
ModuleCategory groups modules by functionality.
const ( CategoryCore ModuleCategory = "core" CategoryProxy ModuleCategory = "proxy" CategorySecurity ModuleCategory = "security" CategoryAuth ModuleCategory = "auth" CategoryUI ModuleCategory = "ui" CategoryCompliance ModuleCategory = "compliance" CategoryAnalytics ModuleCategory = "analytics" CategoryAI ModuleCategory = "ai" )
type ModuleConfig ¶
type ModuleConfig struct {
Enabled bool `json:"enabled"`
Priority int `json:"priority"`
Settings map[string]interface{} `json:"settings,omitempty"`
LicenseKey string `json:"license_key,omitempty"`
}
ModuleConfig contains runtime configuration for a module.
type ModuleLifecycle ¶
type ModuleLifecycle struct {
OnBeforeStart func(ctx context.Context) error
OnAfterStart func(ctx context.Context) error
OnBeforeStop func(ctx context.Context) error
OnAfterStop func(ctx context.Context) error
OnError func(ctx context.Context, err error)
}
ModuleLifecycle represents lifecycle event callbacks.
type ModuleMetadata ¶
type ModuleMetadata struct {
ID string `json:"id"`
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
Author string `json:"author"`
Category ModuleCategory `json:"category"`
Tier Tier `json:"tier"`
Tags []string `json:"tags,omitempty"`
Website string `json:"website,omitempty"`
Repository string `json:"repository,omitempty"`
License string `json:"license,omitempty"`
Config map[string]interface{} `json:"config,omitempty"`
}
ModuleMetadata contains descriptive information about a module.
type ModuleStatus ¶
type ModuleStatus int
ModuleStatus represents the current state of a module.
const ( // StatusUnregistered indicates the module is not registered with the system. StatusUnregistered ModuleStatus = iota // StatusRegistered indicates the module is registered but not initialized. StatusRegistered // StatusInitialized indicates the module has been initialized. StatusInitialized // StatusActive indicates the module is fully active and operational. StatusActive // StatusDisabled indicates the module is temporarily disabled. StatusDisabled // StatusError indicates the module encountered an error. StatusError )
func (ModuleStatus) String ¶
func (s ModuleStatus) String() string
type ModuleWithConfig ¶
type ModuleWithConfig interface {
Module
ValidateConfig(config ModuleConfig) error
DefaultConfig() ModuleConfig
}
ModuleWithConfig is an optional interface for modules with custom config validation.
type ModuleWithLifecycle ¶
type ModuleWithLifecycle interface {
Module
Lifecycle() *ModuleLifecycle
}
ModuleWithLifecycle is an optional interface for modules with lifecycle hooks.
type ModuleWithMetrics ¶
ModuleWithMetrics is an optional interface for modules that expose metrics.
type ModuleWithRoutes ¶
ModuleWithRoutes is an optional interface for modules that register HTTP routes.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages all registered modules and their lifecycle.
func NewRegistry ¶
func NewRegistry(config *RegistryConfig) *Registry
NewRegistry creates a new module registry.
func (*Registry) GetCapability ¶
func (r *Registry) GetCapability(capID string) (*Capability, bool)
GetCapability returns the module providing a capability.
func (*Registry) GetConfig ¶
func (r *Registry) GetConfig(id string) (ModuleConfig, bool)
GetConfig returns the current configuration for a module.
func (*Registry) GetStatus ¶
func (r *Registry) GetStatus(id string) ModuleStatus
GetStatus returns the current status of a module.
func (*Registry) HasCapability ¶
HasCapability checks if a capability is available.
func (*Registry) Health ¶
func (r *Registry) Health(ctx context.Context) map[string]HealthStatus
Health returns health status for all modules.
func (*Registry) Initialize ¶
Initialize initializes all registered modules in dependency order.
func (*Registry) ListByCategory ¶
func (r *Registry) ListByCategory(category ModuleCategory) []string
ListByCategory returns module IDs for a specific category.
func (*Registry) ListByTier ¶
ListByTier returns module IDs for a specific tier.
func (*Registry) SetConfig ¶
func (r *Registry) SetConfig(id string, config ModuleConfig) error
SetConfig updates the configuration for a module.
func (*Registry) Unregister ¶
Unregister removes a module from the registry.
type RegistryConfig ¶
RegistryConfig contains configuration for the registry.
type Tier ¶
type Tier int
Tier represents the licensing tier for a module. Updated to 4-tier system: Community -> Developer -> Professional -> Enterprise
func GetRequiredTier ¶
GetRequiredTier returns the tier required for a feature
func GetTierByName ¶
GetTierByName returns Tier from string name (case insensitive)
func (Tier) GetPriceInfo ¶
GetPriceInfo returns pricing information for a tier
func (Tier) GetTierLimits ¶
func (t Tier) GetTierLimits() TierLimits
GetTierLimits returns resource limits for a tier
func (Tier) GetUpgradePath ¶
GetUpgradePath returns the next tier to upgrade to
func (Tier) MarshalJSON ¶
MarshalJSON implements json.Marshaler for Tier.
func (*Tier) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler for Tier.
type TierLimits ¶
type TierLimits struct {
// Rate Limits
MaxRequestsPerMinute int
MaxConcurrentConnections int
MaxBurstRequests int
// Resource Limits
MaxUsers int
MaxAPIKeys int
MaxTenants int
// Storage Limits
LogRetentionDays int
MaxLogSizeMB int
DataRetentionDays int
// Feature Limits
MaxCustomRules int
MaxWebhooks int
MaxCustomDomains int
// Support
SupportLevel string
}
TierLimits defines resource constraints per tier
func (TierLimits) FormatLimit ¶
func (l TierLimits) FormatLimit(fieldName string) string
FormatLimit returns a human-readable string for a limit
func (TierLimits) RequiresUpgrade ¶
func (l TierLimits) RequiresUpgrade(limitType string, value int) bool
RequiresUpgrade checks if current limits require a tier upgrade