Documentation
¶
Index ¶
- Variables
- func MustResolve[T any](sr *ServiceRegistry, key string) T
- func Resolve[T any](sr *ServiceRegistry, key string) (T, error)
- type AppContext
- type ConfigProvider
- type Configurable
- type Database
- type Disableable
- type DomainPlugin
- type Event
- type EventBus
- type EventHandler
- type EventSubscriber
- type HealthReporter
- type Installable
- type MapConfigProvider
- type MiddlewareProvider
- type ModelProvider
- type Plugin
- type PluginConfigEntry
- func (c *PluginConfigEntry) Bind(target any) error
- func (c *PluginConfigEntry) Get(key string) (any, bool)
- func (c *PluginConfigEntry) GetBool(key string, defaultVal bool) bool
- func (c *PluginConfigEntry) GetInt(key string, defaultVal int) int
- func (c *PluginConfigEntry) GetString(key string, defaultVal string) string
- func (c *PluginConfigEntry) IsEnabled() bool
- type PluginOptions
- type PluginState
- type ResolvedDomainInfo
- type RouteProvider
- type ServiceRegistry
- type Subject
- type Subscription
- type Uninstallable
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBusClosed is returned when publishing to a closed EventBus. ErrBusClosed = errors.New("event bus is closed") // ErrPublishTimeout is returned when the publish buffer is full and context expires. ErrPublishTimeout = errors.New("event publish timeout: buffer full") )
Functions ¶
func MustResolve ¶
func MustResolve[T any](sr *ServiceRegistry, key string) T
MustResolve retrieves a service, panicking if not found or wrong type.
Types ¶
type AppContext ¶
type AppContext struct {
Router chi.Router
DB Database
Redis *redis.Client
Logger *zap.Logger
Services *ServiceRegistry
Config ConfigProvider
Events EventBus
}
AppContext is the typed dependency injection context passed to all plugin lifecycle methods.
type ConfigProvider ¶
type ConfigProvider interface {
Get(key string) (any, bool)
GetString(key string, defaultVal string) string
GetInt(key string, defaultVal int) int
GetBool(key string, defaultVal bool) bool
Bind(target any) error
IsEnabled() bool
}
ConfigProvider gives plugins type-safe access to their scoped configuration.
func EmptyConfig ¶
func EmptyConfig() ConfigProvider
EmptyConfig returns a ConfigProvider that always returns defaults.
type Configurable ¶
type Configurable interface {
PluginOptions() PluginOptions
}
Configurable -- declare plugin options (optional flag, description).
type Database ¶
type Database interface {
Close() error
}
Database is the minimal interface for DB lifecycle management. Keeps frame-core decoupled from specific generated Ent clients.
type Disableable ¶
type Disableable interface {
Disable(ctx context.Context, app *AppContext) error
}
Disableable -- cleanup on shutdown (release resources, flush buffers).
type DomainPlugin ¶
type DomainPlugin interface {
TypeCode() string
ResolveDomain(ctx context.Context, r *http.Request) (*ResolvedDomainInfo, bool, error)
ValidateMembership(ctx context.Context, domainID uuid.UUID, subject Subject) (bool, error)
}
DomainPlugin is an optional capability for plugins that register a domain type.
type Event ¶
type Event struct {
Name string // e.g. "user.created"
Data any // payload
Source string // originating plugin name
Timestamp time.Time // when the event was created
}
Event represents a system or plugin event.
type EventBus ¶
type EventBus interface {
// Publish sends an event. Blocks if buffer is full until ctx expires.
Publish(ctx context.Context, event Event) error
// Subscribe registers a handler for a topic. Returns a Subscription for unsubscribing.
Subscribe(topic string, handler EventHandler) Subscription
// Close drains pending events and waits for in-flight handlers to complete.
Close() error
}
EventBus is the single event mechanism for plugin communication.
type EventHandler ¶
EventHandler is the typed handler for events.
type EventSubscriber ¶
type EventSubscriber interface {
SubscribeEvents(bus EventBus)
}
EventSubscriber -- subscribe to system/plugin events.
type HealthReporter ¶
HealthReporter -- provide custom health checks.
type Installable ¶
type Installable interface {
Install(ctx context.Context, app *AppContext) error
}
Installable -- first-time setup (DB migrations, seed data).
type MapConfigProvider ¶
type MapConfigProvider = PluginConfigEntry
MapConfigProvider is a simple ConfigProvider backed by a map. Used for testing and inline configuration.
type MiddlewareProvider ¶
MiddlewareProvider -- register HTTP middleware.
type ModelProvider ¶
type ModelProvider interface {
RegisterModels() []any
}
ModelProvider -- declare Ent ORM models for auto-migration.
type Plugin ¶
type Plugin interface {
Name() string
Version() string
Dependencies() []string
Enable(ctx context.Context, app *AppContext) error
}
Plugin is the minimal interface every plugin must implement.
type PluginConfigEntry ¶
type PluginConfigEntry struct {
// contains filtered or unexported fields
}
PluginConfigEntry represents a single plugin's configuration entry.
func NewMapConfigProvider ¶
func NewMapConfigProvider(settings map[string]any) *PluginConfigEntry
NewMapConfigProvider creates a ConfigProvider from a settings map (always enabled).
func NewPluginConfigEntry ¶
func NewPluginConfigEntry(name string, enabled bool, settings map[string]any) *PluginConfigEntry
NewPluginConfigEntry creates a plugin config entry.
func (*PluginConfigEntry) Bind ¶
func (c *PluginConfigEntry) Bind(target any) error
func (*PluginConfigEntry) GetBool ¶
func (c *PluginConfigEntry) GetBool(key string, defaultVal bool) bool
func (*PluginConfigEntry) GetInt ¶
func (c *PluginConfigEntry) GetInt(key string, defaultVal int) int
func (*PluginConfigEntry) GetString ¶
func (c *PluginConfigEntry) GetString(key string, defaultVal string) string
func (*PluginConfigEntry) IsEnabled ¶
func (c *PluginConfigEntry) IsEnabled() bool
type PluginOptions ¶
type PluginOptions struct {
Optional bool // If true, failure does not abort bootstrap.
Description string // Human-readable description.
}
PluginOptions holds declarative metadata about a plugin.
type PluginState ¶
type PluginState int
PluginState represents the lifecycle state of a plugin.
const ( StateRegistered PluginState = iota // Registered, not yet processed StateInstalled // Install() succeeded StateEnabled // Enable() succeeded, running StateDisabled // Disable() succeeded, stopped StateFailed // Install() or Enable() failed )
func (PluginState) IsTerminal ¶
func (s PluginState) IsTerminal() bool
IsTerminal returns true if the state cannot transition further in normal flow.
func (PluginState) String ¶
func (s PluginState) String() string
String returns a human-readable state name.
type ResolvedDomainInfo ¶
type ResolvedDomainInfo struct {
DomainID uuid.UUID `json:"domainId"`
TypeCode string `json:"typeCode"`
Key string `json:"key"`
DisplayName string `json:"displayName"`
}
ResolvedDomainInfo holds resolved domain metadata from a DomainPlugin.
type RouteProvider ¶
RouteProvider -- register HTTP routes.
type ServiceRegistry ¶
type ServiceRegistry struct {
// contains filtered or unexported fields
}
ServiceRegistry provides type-safe, namespace-aware service registration and lookup. Services are keyed by "pluginName.serviceName" (e.g. "audit.service", "rbac.enforcer").
func NewServiceRegistry ¶
func NewServiceRegistry() *ServiceRegistry
NewServiceRegistry creates an empty service registry.
func (*ServiceRegistry) Has ¶
func (sr *ServiceRegistry) Has(key string) bool
Has returns true if a service is registered under the given key.
func (*ServiceRegistry) Keys ¶
func (sr *ServiceRegistry) Keys() []string
Keys returns all registered service keys, sorted alphabetically.
func (*ServiceRegistry) MustRegister ¶
func (sr *ServiceRegistry) MustRegister(key string, svc any)
MustRegister stores a service, panicking on duplicate.
type Subscription ¶
type Subscription interface {
Unsubscribe()
}
Subscription represents an active event subscription.
type Uninstallable ¶
type Uninstallable interface {
Uninstall(ctx context.Context, app *AppContext) error
}
Uninstallable -- permanent removal (drop tables, delete files).