-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathstatus.go
39 lines (32 loc) · 1.1 KB
/
status.go
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
package onet
// Status holds key/value pairs of the status to be returned to the requester.
type Status struct {
Field map[string]string
}
// StatusReporter is the interface that all structures that want to return a status will implement.
type StatusReporter interface {
GetStatus() *Status
}
// statusReporterStruct holds a map of all StatusReporters.
type statusReporterStruct struct {
statusReporters map[string]StatusReporter
}
// newStatusReporterStruct creates a new instance of the newStatusReporterStruct.
func newStatusReporterStruct() *statusReporterStruct {
return &statusReporterStruct{
statusReporters: make(map[string]StatusReporter),
}
}
// RegisterStatusReporter registers a status reporter.
func (s *statusReporterStruct) RegisterStatusReporter(name string, sr StatusReporter) {
s.statusReporters[name] = sr
}
// ReportStatus gets the status of all StatusReporters within the Registry and
// puts them in a map
func (s *statusReporterStruct) ReportStatus() map[string]*Status {
m := make(map[string]*Status)
for key, val := range s.statusReporters {
m[key] = val.GetStatus()
}
return m
}