types

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceStatusHealthy   = "healthy"
	ServiceStatusUnhealthy = "unhealthy"
	ServiceStatusUnknown   = "unknown"
)

Service Status constants

View Source
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 added in v0.1.2

func ExtractEventPayload(data any) (*map[string]any, error)

ExtractEventPayload Extract payload from event data

func GetStrongDependencies added in v0.1.2

func GetStrongDependencies(deps []DependencyEntry) []string

GetStrongDependencies filters and returns only strong dependencies

func GetWeakDependencies added in v0.1.2

func GetWeakDependencies(deps []DependencyEntry) []string

GetWeakDependencies filters and returns only weak dependencies

func SafeGet added in v0.1.2

func SafeGet[T any](payload *map[string]any, key string) T

SafeGet safely extracts a value from a payload with type assertion Usage: value := SafeGet[string](payload, "key") Returns zero value of T if key doesn't exist or value can't be converted to T

func SafeGetOr added in v0.1.2

func SafeGetOr[T any](payload *map[string]any, key string, orElse func() T) T

SafeGetOr safely extracts a value with a provided function for handling missing/nil values Usage: value := SafeGetOr(payload, "key", func() T { return computedDefault })

func SafeGetWithDefault added in v0.1.2

func SafeGetWithDefault[T any](payload *map[string]any, key string, defaultValue T) T

SafeGetWithDefault safely extracts a value with a default fallback Usage: value := SafeGetWithDefault(payload, "key", defaultValue)

Types

type DependencyEntry added in v0.1.2

type DependencyEntry struct {
	Name string
	Type DependencyType
}

DependencyEntry represents a dependency with its type

type DependencyType added in v0.1.2

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 added in v0.1.2

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 Handler

type Handler any

Handler represents the handler for an extension

type Interface

type Interface interface {
	// Name returns the name of the extension
	Name() string
	// Init initializes the extension with the given config
	Init(conf *config.Config, m ManagerInterface) error
	// GetHandlers returns the handlers for the extension
	GetHandlers() Handler
	// GetServices returns the services for the extension
	GetServices() Service
	// GetMetadata returns the metadata of the extension
	GetMetadata() Metadata
	// Version returns the version of the extension
	Version() string
	// Dependencies returns the strong dependencies of the extension
	Dependencies() []string
	// OptionalMethods returns the optional methods of the extension
	OptionalMethods
}

Interface defines the structure for an extension (Plugin / Module)

type ManagerInterface

type ManagerInterface interface {
	GetConfig() *config.Config
	Register(ext Interface) error
	InitExtensions() error
	GetExtension(name string) (Interface, error)
	GetExtensions() map[string]*Wrapper
	Cleanup()

	GetHandler(name string) (Handler, error)
	GetHandlers() map[string]Handler
	GetService(name string) (Service, error)
	GetServices() map[string]Service
	GetMetadata() map[string]Metadata
	GetStatus() map[string]string

	LoadPlugins() error
	LoadPlugin(path string) error
	ReloadPlugin(name string) error
	UnloadPlugin(name string) error
	ReloadPlugins() 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

	GetEventBusMetrics() map[string]any
}

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 added in v0.1.2

func (o *OptionalImpl) GetAllDependencies() []DependencyEntry

GetAllDependencies returns all dependencies with their types

func (*OptionalImpl) GetServiceInfo

func (o *OptionalImpl) GetServiceInfo() *ServiceInfo

GetServiceInfo returns service registration info if NeedServiceDiscovery returns true

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 {
	// GetAllDependencies returns all dependencies with their types (Optional)
	GetAllDependencies() []DependencyEntry
	// PreInit performs any necessary setup before initialization
	PreInit() error
	// PostInit performs any necessary setup after initialization
	PostInit() error
	// RegisterRoutes registers routes for the extension (optional)
	RegisterRoutes(router *gin.RouterGroup)
	// PreCleanup performs any necessary cleanup before the main cleanup
	PreCleanup() error
	// Cleanup cleans up the extension
	Cleanup() error
	// Status returns the status of the extension
	Status() string
	// NeedServiceDiscovery returns if the extension needs to be registered as a service
	NeedServiceDiscovery() bool
	// GetServiceInfo returns service registration info if NeedServiceDiscovery returns true
	GetServiceInfo() *ServiceInfo
}

OptionalMethods represents the 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 Service

type Service any

Service represents the service for an extension

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

type ServiceInfo

type ServiceInfo struct {
	Address string            `json:"address"`
	Tags    []string          `json:"tags"`
	Meta    map[string]string `json:"meta"`
}

ServiceInfo contains information needed for service registration

type Wrapper

type Wrapper struct {
	// Metadata is the metadata of the extension
	Metadata Metadata `json:"metadata"`
	// Instance is the instance of the extension
	Instance Interface `json:"instance,omitempty"`
}

Wrapper wraps an Interface instance with its metadata

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL