core

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load[T loader.Library](args ...any) (T, error)

func LoadConfigModule

func LoadConfigModule[T config.Configurable](name string, c T, file string, path []string) error

func LoadDefaultConfigModule

func LoadDefaultConfigModule[T config.Configurable](name string, c T) error

func LoadLibrary

func LoadLibrary[T loader.Library](singleton bool, key *string, args ...any) (T, error)

LoadLibrary is a convenience function that works with concrete types

func LoadMulti

func LoadMulti[T loader.Library](key string, args ...any) (T, error)

func Unload

func Unload[T loader.Library](args ...any) (T, error)

func UnloadLibrary

func UnloadLibrary[T loader.Library](singleton bool, key *string, args ...any) (T, error)

func UnloadMulti

func UnloadMulti[T loader.Library](key string, args ...any) (T, error)

Types

type App

type App struct {
	Context        *AppContext
	ModuleManager  *ModuleManager
	LibraryManager *LibraryManager
}

func Instance

func Instance() *App

func NewApp

func NewApp(ctx context.Context, cfg *config.Config, loaders map[string]LibraryLoader, packages []Module) *App

NewApp creates a new application instance

func (*App) GetLibraryManager

func (a *App) GetLibraryManager() *LibraryManager

GetLibraryManager returns the library manager instance

func (*App) GetModuleManager

func (a *App) GetModuleManager() *ModuleManager

GetModuleManager returns the central registry instance

func (*App) GetSharedContext

func (a *App) GetSharedContext() *AppContext

GetSharedContext returns the shared dependencies

func (*App) Load

func (a *App) Load() *App

func (*App) Start

func (a *App) Start() error

Start starts the application

func (*App) Stop

func (a *App) Stop() error

Stop stops the application gracefully

type AppContext

type AppContext struct {
	Context  context.Context
	Config   *config.Config
	Web      *fiber.App
	Root     fiber.Router
	EventBus *EventBus
}

Context represents shared dependencies that can be injected into modules

func (*AppContext) Destroy

func (a *AppContext) Destroy() error

Destroy release all resources

func (*AppContext) GetDefaultInstance

func (a *AppContext) GetDefaultInstance(name string, key string) (loader.Library, bool)

func (*AppContext) GetDefaultLibraryLoader

func (a *AppContext) GetDefaultLibraryLoader(name string) (LibraryLoader, error)

func (*AppContext) GetDefaultSingletonInstance

func (a *AppContext) GetDefaultSingletonInstance(name string) (loader.Library, bool)

func (*AppContext) GetInstance

func (a *AppContext) GetInstance(name string, key string) (loader.Library, bool)

func (*AppContext) GetLibraryLoader

func (a *AppContext) GetLibraryLoader(name string) (LibraryLoader, error)

func (*AppContext) GetSingletonInstance

func (a *AppContext) GetSingletonInstance(name string) (loader.Library, bool)

func (*AppContext) LoadInstance

func (a *AppContext) LoadInstance(loader LibraryLoader, key string, args ...any) (loader.Library, error)

func (*AppContext) LoadSingletonInstance

func (a *AppContext) LoadSingletonInstance(loader LibraryLoader, args ...any) (loader.Library, error)

func (*AppContext) Start

func (a *AppContext) Start() error

type EventBus

type EventBus struct {
	// contains filtered or unexported fields
}

EventBus represents shared event bus

func NewEventBus

func NewEventBus() *EventBus

NewEventBus creates a new event bus instance

func (*EventBus) GetSubscribers

func (eb *EventBus) GetSubscribers(event string) int

GetSubscribers returns the number of subscribers for an event

func (*EventBus) Publish

func (eb *EventBus) Publish(event string, data any)

Publish publishes an event

func (*EventBus) Subscribe

func (eb *EventBus) Subscribe(event string, handler func(any))

Subscribe subscribes to an event

type LibraryLoader

type LibraryLoader interface {
	SetName(name string)
	Name() string
	Init(args ...any) (loader.Library, error)
}

func GetLibraryLoader

func GetLibraryLoader(name string) (LibraryLoader, bool)

type LibraryManager

type LibraryManager struct {
	Loaders   map[string]LibraryLoader
	Libraries map[string]map[string]loader.Library // Loaded libraries
}

func CreateLibraryManager

func CreateLibraryManager(loaders map[string]LibraryLoader) *LibraryManager

func (*LibraryManager) Destroy

func (lm *LibraryManager) Destroy() error

func (*LibraryManager) GetInstance

func (lm *LibraryManager) GetInstance(name string, key string) (loader.Library, bool)

func (*LibraryManager) GetLibrary

func (lm *LibraryManager) GetLibrary(name string, singleton bool, key *string) (loader.Library, bool)

GetLibrary retrieves a library instance

func (*LibraryManager) GetLoader

func (lm *LibraryManager) GetLoader(name string) (LibraryLoader, bool)

func (*LibraryManager) GetSingletonInstance

func (lm *LibraryManager) GetSingletonInstance(name string) (loader.Library, bool)

func (*LibraryManager) LoadFromLoader

func (lm *LibraryManager) LoadFromLoader(load LibraryLoader, name string, singleton bool, key *string, args ...any) (loader.Library, error)

func (*LibraryManager) LoadInstance

func (lm *LibraryManager) LoadInstance(libType reflect.Type, key string, args ...any) (loader.Library, error)

func (*LibraryManager) LoadInstanceFromLoader

func (lm *LibraryManager) LoadInstanceFromLoader(loader LibraryLoader, key string, args ...any) (loader.Library, error)

func (*LibraryManager) LoadLibrary

func (lm *LibraryManager) LoadLibrary(libType reflect.Type, singleton bool, key *string, args ...any) (loader.Library, error)

LoadLibrary creates or retrieves a library instance

func (*LibraryManager) LoadSingleton

func (lm *LibraryManager) LoadSingleton(libType reflect.Type, args ...any) (loader.Library, error)

func (*LibraryManager) LoadSingletonFromLoader

func (lm *LibraryManager) LoadSingletonFromLoader(loader LibraryLoader, args ...any) (loader.Library, error)

func (*LibraryManager) UnloadInstance

func (lm *LibraryManager) UnloadInstance(libType reflect.Type, key string) (loader.Library, error)

func (*LibraryManager) UnloadLibrary

func (lm *LibraryManager) UnloadLibrary(libType reflect.Type, singleton bool, key *string) (loader.Library, error)

func (*LibraryManager) UnloadSingleton

func (lm *LibraryManager) UnloadSingleton(libType reflect.Type) (loader.Library, error)

type LoadedModule

type LoadedModule struct {
	Name      string
	Path      string
	Module    Module
	Plugin    *plugin.Plugin
	LoadedAt  string
	DependsOn []string
}

LoadedModule represents a loaded module and its metadata

type Module

type Module interface {
	// Name returns the unique name of the module
	Name() string

	// Version returns the version of the module
	Version() string

	// Dependencies returns the dependencies of the module
	Dependencies() []string

	// Config returns the module-specific configuration
	Config() config.Configurable

	// Routes returns the routes provided by this module
	Routes() []*ModuleRoute

	// Services returns the services provided by this module
	Services() map[string]any

	// Repositories returns the repositories provided by this module
	Repositories() map[string]any

	// Init initializes the module with the given app and dependencies
	Init(ctx *AppContext) error

	Destroy() error
}

Module represents a pluggable module interface

type ModuleManager

type ModuleManager struct {
	// contains filtered or unexported fields
}

ModuleManager manages module registration and loading

func CreateModuleManager

func CreateModuleManager(config *config.ModuleConfig, modules []Module) *ModuleManager

CreateModuleManager creates a new central registry instance

func (*ModuleManager) AutoLoadModulesFromConfig

func (r *ModuleManager) AutoLoadModulesFromConfig() error

AutoLoadModulesFromConfig automatically loads modules from configured paths

func (*ModuleManager) AutoLoadModulesFromPath

func (r *ModuleManager) AutoLoadModulesFromPath(modulePaths []string) error

AutoLoadModulesFromPath automatically loads modules from specified paths

func (*ModuleManager) Destroy

func (lm *ModuleManager) Destroy() error

func (*ModuleManager) GetLoadedModules

func (r *ModuleManager) GetLoadedModules() []LoadedModule

GetLoadedModules returns all loaded modules with their metadata

func (*ModuleManager) GetModule

func (r *ModuleManager) GetModule(name string) (Module, error)

GetModule retrieves a registered module by name

func (*ModuleManager) GetModuleMetadata

func (r *ModuleManager) GetModuleMetadata(name string) (LoadedModule, error)

GetModuleMetadata returns metadata for a specific loaded module

func (*ModuleManager) GetRepositories

func (r *ModuleManager) GetRepositories() map[string]any

GetRepositories returns all repositories from all registered modules

func (*ModuleManager) GetRoutes

func (r *ModuleManager) GetRoutes() []*ModuleRoute

GetRoutes returns all routes from all registered modules

func (*ModuleManager) GetServices

func (r *ModuleManager) GetServices() map[string]any

GetServices returns all services from all registered modules

func (*ModuleManager) InitializeModules

func (r *ModuleManager) InitializeModules() error

InitializeModules initializes all registered modules with the app and dependencies

func (*ModuleManager) InitializeModulesWithDependencies

func (r *ModuleManager) InitializeModulesWithDependencies() error

InitializeModulesWithDependencies initializes modules in dependency order

func (*ModuleManager) IsLoaded

func (r *ModuleManager) IsLoaded() bool

IsLoaded checks if all modules have been initialized

func (*ModuleManager) ListModules

func (r *ModuleManager) ListModules() []string

ListModules returns all registered module names

func (*ModuleManager) LoadModuleFromGit

func (r *ModuleManager) LoadModuleFromGit(repoURL, branch, path string) error

LoadModuleFromGit loads a module from a git repository

func (*ModuleManager) LoadModuleFromPackage

func (r *ModuleManager) LoadModuleFromPackage(modulePath string) error

LoadModuleFromPackage loads a module using go module path

func (*ModuleManager) LoadModuleFromPath

func (r *ModuleManager) LoadModuleFromPath(path string) error

LoadModuleFromPath loads a module from a file path

func (*ModuleManager) Register

func (r *ModuleManager) Register(module Module) error

Register registers a new module with the central registry

func (*ModuleManager) UnloadModule

func (r *ModuleManager) UnloadModule(name string) error

UnloadModule unloads a module by name

type ModuleRoute

type ModuleRoute struct {
	Method  string
	Path    string
	Handler fiber.Handler
	Root    fiber.Router
}

func AppendRouteToArray

func AppendRouteToArray(routes []*ModuleRoute, route *ModuleRoute) []*ModuleRoute

Jump to

Keyboard shortcuts

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