full unit testing and fixes
- mapToString is ordered according to setup - setupSingle & teardownSingle no longer return "ok" states - teardown functions support errors - setup and teardown functions receive module
This commit is contained in:
15
module.go
15
module.go
@@ -1,17 +1,24 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
// ErrModuleNotFound is returned when a module is not found in the lifecycle.
|
||||
var ErrModuleNotFound = errors.New("module not found")
|
||||
|
||||
// moduleFn is a function type for module setup and teardown functions.
|
||||
type moduleFn func(*Module) error
|
||||
|
||||
// Module represents a sub-system of the application, with its setup and
|
||||
// teardown functions and dependencies.
|
||||
type Module struct {
|
||||
logger *slog.Logger
|
||||
name string
|
||||
setup setupFn
|
||||
teardown teardownFn
|
||||
setup moduleFn
|
||||
teardown moduleFn
|
||||
depends []string
|
||||
loaded bool // loaded indicates if the module has been set up
|
||||
}
|
||||
@@ -19,9 +26,9 @@ type Module struct {
|
||||
// ModuleOpts contains user-exposed options when defining a module.
|
||||
type ModuleOpts struct {
|
||||
// Setup is the setup function for the module.
|
||||
Setup setupFn
|
||||
Setup moduleFn
|
||||
// Teardown is the teardown function for the module.
|
||||
Teardown teardownFn
|
||||
Teardown moduleFn
|
||||
// Depends is a list of modules that this module depends on. Each entry must
|
||||
// be the exact name of a module registered in the lifecycle.
|
||||
Depends []string
|
||||
|
||||
Reference in New Issue
Block a user