mirror of
https://github.com/safing/portbase
synced 2025-09-01 10:09:50 +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
|
||||
}
|
||||
|
||||
func dummyAction() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Register registers a new module.
|
||||
func Register(name string, prep, start, stop func() error, dependencies ...string) *Module {
|
||||
newModule := &Module{
|
||||
|
@ -43,6 +47,18 @@ func Register(name string, prep, start, stop func() error, dependencies ...strin
|
|||
stop: stop,
|
||||
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()
|
||||
defer modulesLock.Unlock()
|
||||
modulesOrder = append(modulesOrder, newModule)
|
||||
|
|
Loading…
Add table
Reference in a new issue