mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-29 18:00:51 +01:00
feat: added modules
This commit is contained in:
30
core/utils/init.go
Normal file
30
core/utils/init.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/crawlab-team/crawlab/core/interfaces"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var moduleInitializedMap = sync.Map{}
|
||||
|
||||
func InitModule(id interfaces.ModuleId, fn func() error) (err error) {
|
||||
res, ok := moduleInitializedMap.Load(id)
|
||||
if ok {
|
||||
initialized, _ := res.(bool)
|
||||
if initialized {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if err := fn(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
moduleInitializedMap.Store(id, true)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ForceInitModule(fn func() error) (err error) {
|
||||
return fn()
|
||||
}
|
||||
Reference in New Issue
Block a user