mirror of
https://github.com/safing/portbase
synced 2025-09-04 03:29:59 +00:00
Allow nil functions for modules
This commit is contained in:
parent
ea9592a536
commit
ddc5465b08
1 changed files with 16 additions and 0 deletions
|
@ -33,6 +33,10 @@ type Module struct {
|
||||||
dependencies []string
|
dependencies []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func dummyAction() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Register registers a new module.
|
// Register registers a new module.
|
||||||
func Register(name string, prep, start, stop func() error, dependencies ...string) *Module {
|
func Register(name string, prep, start, stop func() error, dependencies ...string) *Module {
|
||||||
newModule := &Module{
|
newModule := &Module{
|
||||||
|
@ -43,6 +47,18 @@ func Register(name string, prep, start, stop func() error, dependencies ...strin
|
||||||
stop: stop,
|
stop: stop,
|
||||||
dependencies: dependencies,
|
dependencies: dependencies,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// replace nil arguments with dummy action
|
||||||
|
if newModule.prep == nil {
|
||||||
|
newModule.prep = dummyAction
|
||||||
|
}
|
||||||
|
if newModule.start == nil {
|
||||||
|
newModule.start = dummyAction
|
||||||
|
}
|
||||||
|
if newModule.stop == nil {
|
||||||
|
newModule.stop = dummyAction
|
||||||
|
}
|
||||||
|
|
||||||
modulesLock.Lock()
|
modulesLock.Lock()
|
||||||
defer modulesLock.Unlock()
|
defer modulesLock.Unlock()
|
||||||
modulesOrder = append(modulesOrder, newModule)
|
modulesOrder = append(modulesOrder, newModule)
|
||||||
|
|
Loading…
Add table
Reference in a new issue