daemon: use per-interface features

Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
Steffen Vogel
2022-09-30 08:32:26 +02:00
parent 70e437d9a6
commit 92a7ad2f7f
99 changed files with 3510 additions and 2599 deletions

43
pkg/daemon/feature.go Normal file
View 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
}