draincloud-core/internal/plugin/store.go
2024-10-19 19:05:34 -04:00

29 lines
496 B
Go

package plugin
import (
"fmt"
"sync"
)
type PluginStore struct {
m sync.RWMutex
plugins map[string]*Plugin
}
func NewPluginStore() *PluginStore {
return &PluginStore{
plugins: make(map[string]*Plugin),
}
}
func (s *PluginStore) Add(plugin *Plugin) {
s.m.Lock()
defer s.m.Unlock()
s.plugins[PluginStoreKey(plugin.md.Namespace, plugin.md.Name, plugin.md.Version)] = plugin
}
func PluginStoreKey(ns, name string, v int) string {
return fmt.Sprintf("%s.%s.%v", ns, name, v)
}