expose ModuleFn type
This commit is contained in:
3
go.mod
3
go.mod
@@ -6,6 +6,9 @@ require github.com/stretchr/testify v1.10.0
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/kr/text v0.2.0 // indirect
|
||||||
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -1,10 +1,12 @@
|
|||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
12
module.go
12
module.go
@@ -10,8 +10,8 @@ import (
|
|||||||
// ErrModuleNotFound is returned when a module is not found in the lifecycle.
|
// ErrModuleNotFound is returned when a module is not found in the lifecycle.
|
||||||
var ErrModuleNotFound = errors.New("module not found")
|
var ErrModuleNotFound = errors.New("module not found")
|
||||||
|
|
||||||
// moduleFn is a function type for module setup and teardown functions.
|
// ModuleFn is a function type for module setup and teardown functions.
|
||||||
type moduleFn func(*Module) error
|
type ModuleFn func(*Module) error
|
||||||
|
|
||||||
// GenericModule is an interface that allows modules to be extended with custom
|
// GenericModule is an interface that allows modules to be extended with custom
|
||||||
// functionality, as the module can return a pointer to the underlying Module.
|
// functionality, as the module can return a pointer to the underlying Module.
|
||||||
@@ -26,8 +26,8 @@ type Module struct {
|
|||||||
lifecycle *Lifecycle // lifecycle is the parent lifecycle this module belongs to
|
lifecycle *Lifecycle // lifecycle is the parent lifecycle this module belongs to
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
name string
|
name string
|
||||||
setup moduleFn
|
setup ModuleFn
|
||||||
teardown moduleFn
|
teardown ModuleFn
|
||||||
depends []string
|
depends []string
|
||||||
loaded bool // loaded indicates if the module has been set up
|
loaded bool // loaded indicates if the module has been set up
|
||||||
}
|
}
|
||||||
@@ -35,9 +35,9 @@ type Module struct {
|
|||||||
// ModuleOpts contains user-exposed options when defining a module.
|
// ModuleOpts contains user-exposed options when defining a module.
|
||||||
type ModuleOpts struct {
|
type ModuleOpts struct {
|
||||||
// Setup is the setup function for the module.
|
// Setup is the setup function for the module.
|
||||||
Setup moduleFn
|
Setup ModuleFn
|
||||||
// Teardown is the teardown function for the module.
|
// Teardown is the teardown function for the module.
|
||||||
Teardown moduleFn
|
Teardown ModuleFn
|
||||||
// Depends is a list of modules that this module depends on. Each entry must
|
// 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.
|
// be the exact name of a module registered in the lifecycle.
|
||||||
Depends []string
|
Depends []string
|
||||||
|
|||||||
Reference in New Issue
Block a user