38 lines
678 B
Go
38 lines
678 B
Go
package collector
|
|
|
|
import "sync"
|
|
|
|
type Registry struct {
|
|
mu sync.RWMutex
|
|
connectors map[string]Connector
|
|
}
|
|
|
|
func NewRegistry() *Registry {
|
|
return &Registry{
|
|
connectors: make(map[string]Connector),
|
|
}
|
|
}
|
|
|
|
func NewDefaultRegistry() *Registry {
|
|
r := NewRegistry()
|
|
r.Register(NewRedfishConnector())
|
|
r.Register(NewIPMIMockConnector())
|
|
return r
|
|
}
|
|
|
|
func (r *Registry) Register(connector Connector) {
|
|
if connector == nil {
|
|
return
|
|
}
|
|
r.mu.Lock()
|
|
r.connectors[connector.Protocol()] = connector
|
|
r.mu.Unlock()
|
|
}
|
|
|
|
func (r *Registry) Get(protocol string) (Connector, bool) {
|
|
r.mu.RLock()
|
|
connector, ok := r.connectors[protocol]
|
|
r.mu.RUnlock()
|
|
return connector, ok
|
|
}
|