Files
cunicu/pkg/daemon/feature.go
Steffen Vogel 92a7ad2f7f daemon: use per-interface features
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
2022-10-07 18:30:50 +02:00

44 lines
721 B
Go

// 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
}