mirror of
https://codeberg.org/cunicu/cunicu.git
synced 2025-10-05 16:57:01 +08:00
daemon: use per-interface features
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
43
pkg/daemon/feature.go
Normal file
43
pkg/daemon/feature.go
Normal file
@@ -0,0 +1,43 @@
|
||||
// Package feat contains several sub-packages each implementing a dedicated feature.
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
var (
|
||||
Features = map[string]*FeaturePlugin{}
|
||||
plugins []*FeaturePlugin
|
||||
)
|
||||
|
||||
type FeaturePlugin struct {
|
||||
Name string
|
||||
Description string
|
||||
|
||||
New func(i *Interface) (Feature, error)
|
||||
Order int
|
||||
}
|
||||
|
||||
type SyncableFeature interface {
|
||||
Sync() error
|
||||
}
|
||||
|
||||
type Feature interface {
|
||||
Start() error
|
||||
Close() error
|
||||
}
|
||||
|
||||
func SortedFeatures() []*FeaturePlugin {
|
||||
if plugins == nil {
|
||||
for name, feat := range Features {
|
||||
feat.Name = name
|
||||
plugins = append(plugins, feat)
|
||||
}
|
||||
}
|
||||
|
||||
slices.SortFunc(plugins, func(a, b *FeaturePlugin) bool {
|
||||
return a.Order < b.Order
|
||||
})
|
||||
|
||||
return plugins
|
||||
}
|
Reference in New Issue
Block a user