Add pluggable live collectors and simplify API connect form
This commit is contained in:
37
internal/collector/registry.go
Normal file
37
internal/collector/registry.go
Normal file
@@ -0,0 +1,37 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user