core

package
v0.0.37 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load[T port.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 port.Library](singleton bool, key *string, args ...any) (T, error)

LoadLibrary is a convenience function that works with concrete types

func LoadMulti

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

func RegisterRoutes added in v0.0.37

func RegisterRoutes(routes []*ModuleRoute)

RegisterRoutes registers all collected routes onto their routers. Routes are grouped per router and sorted by path priority (static segments before parameterised ones) so that the most specific route is always matched first.

func Unload

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

func UnloadLibrary

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

func UnloadMulti

func UnloadMulti[T port.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
	AuthHandler fiber.Handler
	EventBus    *EventBus
	Hook        *Hook
}

Context represents shared dependencies that can be injected into modules

func (*AppContext) AddHook added in v0.0.30

func (a *AppContext) AddHook(pos string, fn HookFunc)

func (*AppContext) Destroy

func (a *AppContext) Destroy() error

Destroy release all resources

func (*AppContext) GetDefaultInstance

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

func (*AppContext) GetDefaultLibraryLoader

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

func (*AppContext) GetDefaultSingletonInstance

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

func (*AppContext) GetInstance

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

func (*AppContext) GetLibraryLoader

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

func (*AppContext) GetSingletonInstance

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

func (*AppContext) LoadInstance

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

func (*AppContext) LoadSingletonInstance

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

func (*AppContext) RunHook added in v0.0.29

func (a *AppContext) RunHook(pos string)

func (*AppContext) Start

func (a *AppContext) Start() error

func (*AppContext) StartDefaultInstance added in v0.0.24

func (a *AppContext) StartDefaultInstance(name string, key string, args ...any) (port.Library, error)

func (*AppContext) StartDefaultSingletonInstance added in v0.0.24

func (a *AppContext) StartDefaultSingletonInstance(name string, args ...any) (port.Library, error)

func (*AppContext) StartInstance added in v0.0.24

func (a *AppContext) StartInstance(name string, key string, args ...any) (port.Library, error)

func (*AppContext) StartSingletonInstance added in v0.0.24

func (a *AppContext) StartSingletonInstance(name string, args ...any) (port.Library, 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 Hook added in v0.0.29

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

func NewHook added in v0.0.29

func NewHook() *Hook

func (*Hook) AddFunc added in v0.0.29

func (h *Hook) AddFunc(pos string, fn HookFunc)

func (*Hook) RunFunc added in v0.0.29

func (h *Hook) RunFunc(pos string)

type HookFunc added in v0.0.29

type HookFunc func()

type LibraryLoader

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

func GetLibraryLoader

func GetLibraryLoader(name string) (LibraryLoader, bool)

type LibraryManager

type LibraryManager struct {
	Loaders   map[string]LibraryLoader
	Libraries map[string]map[string]port.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) (port.Library, bool)

func (*LibraryManager) GetLibrary

func (lm *LibraryManager) GetLibrary(name string, singleton bool, key *string) (port.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) (port.Library, bool)

func (*LibraryManager) LoadFromLoader

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

func (*LibraryManager) LoadInstance

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

func (*LibraryManager) LoadInstanceFromLoader

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

func (*LibraryManager) LoadLibrary

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

LoadLibrary creates or retrieves a library instance

func (*LibraryManager) LoadSingleton

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

func (*LibraryManager) LoadSingletonFromLoader

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

func (*LibraryManager) UnloadInstance

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

func (*LibraryManager) UnloadLibrary

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

func (*LibraryManager) UnloadSingleton

func (lm *LibraryManager) UnloadSingleton(libType reflect.Type) (port.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.ConfigObject

	// 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 ModuleExtended added in v0.0.32

type ModuleExtended interface {
	Module

	// PostInit call after Init
	PostInit(ctx *AppContext) error
}

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
	Handlers []fiber.Handler
	Root     fiber.Router
}

func AppendRouteToArray

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

AppendRouteToArray collects a route without registering it immediately. Registration is deferred so that, once every route is known, they can be registered with the router in priority order via RegisterRoutes. This keeps a parameterised route such as "/posyandu/:id" from shadowing a static route such as "/posyandu/batch", because Fiber matches routes strictly in registration order and a route cannot be reordered once it has been added.

Jump to

Keyboard shortcuts

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