Documentation
¶
Index ¶
- Constants
- func ExtractEventPayload(data any) (*map[string]any, error)
- func GetServiceInterface(service any, fieldName string) (any, bool)
- func GetStrongDependencies(deps []DependencyEntry) []string
- func GetWeakDependencies(deps []DependencyEntry) []string
- func SafeGet[T any](payload *map[string]any, key string) T
- func SafeGetOr[T any](payload *map[string]any, key string, orElse func() T) T
- func SafeGetWithDefault[T any](payload *map[string]any, key string, defaultValue T) T
- type CallOptions
- type CallResult
- type CallStrategy
- type DependencyEntry
- type DependencyType
- type EventBusInterface
- type EventData
- type EventTarget
- type Handler
- type Interface
- type ManagerInterface
- type Metadata
- type OptionalImpl
- func (o *OptionalImpl) Cleanup() error
- func (o *OptionalImpl) GetAllDependencies() []DependencyEntry
- func (o *OptionalImpl) GetPublisher() any
- func (o *OptionalImpl) GetServiceInfo() *ServiceInfo
- func (o *OptionalImpl) GetSubscriber() any
- func (o *OptionalImpl) NeedServiceDiscovery() bool
- func (o *OptionalImpl) PostInit() error
- func (o *OptionalImpl) PreCleanup() error
- func (o *OptionalImpl) PreInit() error
- func (o *OptionalImpl) RegisterRoutes(router *gin.RouterGroup)
- func (o *OptionalImpl) Status() string
- type OptionalMethods
- type PluginLoaderInterface
- type Service
- type ServiceDiscoveryInterface
- type ServiceInfo
- type Wrapper
Constants ¶
const ( ServiceStatusHealthy = "healthy" ServiceStatusUnhealthy = "unhealthy" ServiceStatusUnknown = "unknown" )
Service Status constants
const ( // StatusActive indicates the extension is running normally StatusActive = "active" // StatusInactive indicates the extension is installed but not running StatusInactive = "inactive" // StatusError indicates the extension encountered an error StatusError = "error" // StatusInitializing indicates the extension is in initialization process StatusInitializing = "initializing" // StatusMaintenance indicates the extension is under maintenance StatusMaintenance = "maintenance" // StatusDisabled indicates the extension has been manually disabled StatusDisabled = "disabled" )
Extension status constants
Variables ¶
This section is empty.
Functions ¶
func ExtractEventPayload ¶
ExtractEventPayload Extract payload from event data
func GetServiceInterface ¶
GetServiceInterface gets interface from service by field name
func GetStrongDependencies ¶
func GetStrongDependencies(deps []DependencyEntry) []string
GetStrongDependencies filters and returns only strong dependencies
func GetWeakDependencies ¶
func GetWeakDependencies(deps []DependencyEntry) []string
GetWeakDependencies filters and returns only weak dependencies
func SafeGet ¶
SafeGet safely extracts a value from a payload Usage: value := SafeGet[string](payload, "key") Returns zero value of T if key doesn't exist or value can't be converted to T
Types ¶
type CallOptions ¶
type CallOptions struct {
Strategy CallStrategy
Timeout time.Duration
}
CallOptions defines options for service calls
type CallResult ¶
type CallResult struct {
Response any
Error error
IsLocal bool
IsRemote bool
Duration time.Duration
}
CallResult represents service call result
type CallStrategy ¶
type CallStrategy int
CallStrategy defines service calling strategy
const ( LocalFirst CallStrategy = iota // Try local first, fallback to remote RemoteFirst // Try remote first, fallback to local LocalOnly // Local only RemoteOnly // Remote only )
type DependencyEntry ¶
type DependencyEntry struct {
Name string
Type DependencyType
}
DependencyEntry represents a dependency with its type
type DependencyType ¶
type DependencyType string
DependencyType defines the type of dependency
const ( // StrongDependency indicates a required dependency StrongDependency DependencyType = "strong" // WeakDependency indicates an optional dependency WeakDependency DependencyType = "weak" )
type EventBusInterface ¶
type EventBusInterface interface {
Subscribe(eventName string, handler func(any))
Publish(eventName string, data any)
PublishWithRetry(eventName string, data any, maxRetries int)
GetMetrics() map[string]any
}
EventBusInterface defines the interface for event bus operations
type EventData ¶
type EventData struct {
Time time.Time `json:"time"`
Source string `json:"source"`
EventType string `json:"event_type"`
Data any `json:"data"`
}
EventData Event data structure
type EventTarget ¶
type EventTarget int
EventTarget defines where an event should be published
const ( EventTargetMemory EventTarget = 1 << iota // In-memory event bus EventTargetQueue // Message queue (RabbitMQ/Kafka) EventTargetAll = EventTargetMemory | EventTargetQueue // All available targets )
type Interface ¶
type Interface interface {
Name() string
Version() string
Init(conf *config.Config, m ManagerInterface) error
GetMetadata() Metadata
GetHandlers() Handler
GetServices() Service
Dependencies() []string
OptionalMethods
}
Interface defines the core structure for an extension
type ManagerInterface ¶
type ManagerInterface interface {
GetConfig() *config.Config
InitExtensions() error
RegisterExtension(ext Interface) error
GetExtensionByName(name string) (Interface, error)
ListExtensions() map[string]*Wrapper
GetHandlerByName(name string) (Handler, error)
ListHandlers() map[string]Handler
GetServiceByName(name string) (Service, error)
ListServices() map[string]Service
GetCrossService(extensionName, servicePath string) (any, error)
RegisterCrossService(key string, service any)
CallService(ctx context.Context, serviceName, methodName string, req any) (*CallResult, error)
CallServiceWithOptions(ctx context.Context, serviceName, methodName string, req any, opts *CallOptions) (*CallResult, error)
LoadPlugins() error
LoadPlugin(path string) error
ReloadPlugin(name string) error
UnloadPlugin(name string) error
GetExtensionPublisher(name string, publisherType reflect.Type) (any, error)
GetExtensionSubscriber(name string, subscriberType reflect.Type) (any, error)
PublishEvent(eventName string, data any, target ...EventTarget)
PublishEventWithRetry(eventName string, data any, maxRetries int, target ...EventTarget)
SubscribeEvent(eventName string, handler func(any), source ...EventTarget)
RegisterConsulService(name string, info *ServiceInfo) error
DeregisterConsulService(name string) error
GetConsulService(name string) (*api.AgentService, error)
CheckServiceHealth(name string) string
GetHealthyServices(name string) ([]*api.ServiceEntry, error)
GetServiceCacheStats() map[string]any
RegisterRoutes(router *gin.Engine)
ManageRoutes(router *gin.RouterGroup)
ExecuteWithCircuitBreaker(extensionName string, fn func() (any, error)) (any, error)
PublishMessage(exchange, routingKey string, body []byte) error
SubscribeToMessages(queue string, handler func([]byte) error) error
GetMetadata() map[string]Metadata
GetStatus() map[string]string
GetEventsMetrics() map[string]any
Cleanup()
Register(ext Interface) error // deprecated: use RegisterExtension
GetExtension(name string) (Interface, error) // deprecated: use GetExtensionByName
GetExtensions() map[string]*Wrapper // deprecated: use ListExtensions
GetHandler(name string) (Handler, error) // deprecated: use GetHandlerByName
GetHandlers() map[string]Handler // deprecated: use ListHandlers
GetService(extensionName string) (Service, error) // deprecated: use GetServiceByName
GetServices() map[string]Service // deprecated: use ListServices
RefreshCrossServices() // deprecated: automatic refresh
}
ManagerInterface defines the interface for extension manager operations
type Metadata ¶
type Metadata struct {
// Name is the name of the extension
Name string `json:"name,omitempty"`
// Version is the version of the extension
Version string `json:"version,omitempty"`
// Dependencies are the dependencies of the extension
Dependencies []string `json:"dependencies,omitempty"`
// Description is the description of the extension
Description string `json:"description,omitempty"`
// Type is the type of the extension, e.g. core, business, plugin, module, etc
Type string `json:"type,omitempty"`
// Group is the belong group of the extension, e.g. iam, res, flow, sys, org, rt, plug, etc
Group string `json:"group,omitempty"`
}
Metadata represents the metadata of an extension
type OptionalImpl ¶
type OptionalImpl struct{}
OptionalImpl implements the optional methods
func (*OptionalImpl) Cleanup ¶
func (o *OptionalImpl) Cleanup() error
Cleanup cleans up the extension
func (*OptionalImpl) GetAllDependencies ¶
func (o *OptionalImpl) GetAllDependencies() []DependencyEntry
GetAllDependencies returns all dependencies
func (*OptionalImpl) GetPublisher ¶
func (o *OptionalImpl) GetPublisher() any
GetPublisher returns the event publisher for the extension
func (*OptionalImpl) GetServiceInfo ¶
func (o *OptionalImpl) GetServiceInfo() *ServiceInfo
GetServiceInfo returns service registration info if NeedServiceDiscovery returns true
func (*OptionalImpl) GetSubscriber ¶
func (o *OptionalImpl) GetSubscriber() any
GetSubscriber returns the event subscriber for the extension
func (*OptionalImpl) NeedServiceDiscovery ¶
func (o *OptionalImpl) NeedServiceDiscovery() bool
NeedServiceDiscovery returns if the extension needs to be registered as a service
func (*OptionalImpl) PostInit ¶
func (o *OptionalImpl) PostInit() error
PostInit performs any necessary setup after initialization
func (*OptionalImpl) PreCleanup ¶
func (o *OptionalImpl) PreCleanup() error
PreCleanup performs any necessary cleanup before the main cleanup
func (*OptionalImpl) PreInit ¶
func (o *OptionalImpl) PreInit() error
PreInit performs any necessary setup before initialization
func (*OptionalImpl) RegisterRoutes ¶
func (o *OptionalImpl) RegisterRoutes(router *gin.RouterGroup)
RegisterRoutes registers routes for the extension
func (*OptionalImpl) Status ¶
func (o *OptionalImpl) Status() string
Status returns the status of the extension
type OptionalMethods ¶
type OptionalMethods interface {
PreInit() error
PostInit() error
PreCleanup() error
Cleanup() error
Status() string
GetAllDependencies() []DependencyEntry
NeedServiceDiscovery() bool
GetServiceInfo() *ServiceInfo
GetPublisher() any
GetSubscriber() any
RegisterRoutes(router *gin.RouterGroup)
}
OptionalMethods represents optional methods for an extension
type PluginLoaderInterface ¶
type PluginLoaderInterface interface {
LoadPlugin(path string, manager ManagerInterface) error
UnloadPlugin(name string) error
GetPlugin(name string) *Wrapper
GetPlugins() map[string]*Wrapper
RegisterPlugin(ext Interface, metadata Metadata)
GetRegisteredPlugins() []*Wrapper
}
PluginLoaderInterface defines the interface for plugin loading/unloading
type ServiceDiscoveryInterface ¶
type ServiceDiscoveryInterface interface {
RegisterService(name string, info *ServiceInfo) error
DeregisterService(name string) error
GetService(name string) (*api.AgentService, error)
CheckServiceHealth(name string) string
GetHealthyServices(name string) ([]*api.ServiceEntry, error)
SetCacheTTL(ttl time.Duration)
ClearCache()
GetCacheStats() map[string]any
}
ServiceDiscoveryInterface defines the interface for service discovery operations