-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitoringControllers.go
More file actions
65 lines (50 loc) · 1.69 KB
/
monitoringControllers.go
File metadata and controls
65 lines (50 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package inforo
import (
"errors"
"sync"
"github.com/laplasd/inforo/api"
"github.com/sirupsen/logrus"
)
type MonitoringControllerRegistry struct {
сontrollers map[string]api.MonitoringController
mu *sync.RWMutex
Logger *logrus.Logger
}
type MonitoringControllerRegistryOptions struct {
Logger *logrus.Logger
// Другие зависимости
}
func NewMonitoringControllerRegistry(opts MonitoringControllerRegistryOptions) (api.MonitoringControllerRegistry, error) {
return &MonitoringControllerRegistry{
mu: &sync.RWMutex{},
Logger: opts.Logger,
сontrollers: make(map[string]api.MonitoringController),
}, nil
}
func (mcr *MonitoringControllerRegistry) Delete(c string) error {
return nil
}
func (mcr *MonitoringControllerRegistry) Get(componentType string) (api.MonitoringController, error) {
if ctl, ok := mcr.сontrollers[componentType]; ok {
return ctl, nil
} else {
return nil, errors.New("controller not found")
}
}
func (mcr *MonitoringControllerRegistry) List() ([]api.MonitoringController, error) {
return []api.MonitoringController{}, nil
}
func (mcr *MonitoringControllerRegistry) Register(controllerType string, controller api.MonitoringController) error {
mcr.mu.Lock()
defer mcr.mu.Unlock()
if _, exists := mcr.сontrollers[controllerType]; exists {
mcr.Logger.Warnf("Component %s already registered", controllerType)
return errors.New("component already registered")
}
mcr.сontrollers[controllerType] = controller
//cr.logger.Infof("Registered component %s (%s) of type %s", comp.ID, comp.Name, comp.Type)
return nil
}
func (mcr *MonitoringControllerRegistry) Update(c string, comp api.MonitoringController) error {
return nil
}