2024-10-17 20:20:42 +00:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PluginStore struct {
|
|
|
|
m sync.RWMutex
|
|
|
|
plugins map[string]*Plugin
|
|
|
|
}
|
|
|
|
|
2024-10-19 23:05:34 +00:00
|
|
|
func NewPluginStore() *PluginStore {
|
|
|
|
return &PluginStore{
|
|
|
|
plugins: make(map[string]*Plugin),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-17 20:20:42 +00:00
|
|
|
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)
|
|
|
|
}
|