| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package registry |
| 5 |
|
| 6 |
var registry []*Entry = make([]*Entry, 0) |
| 7 |
|
| 8 |
|
| 9 |
type Entry struct { |
| 10 |
source func() string |
| 11 |
active bool |
| 12 |
} |
| 13 |
|
| 14 |
|
| 15 |
func newEntry(source func() string) *Entry { |
| 16 |
return &Entry{ |
| 17 |
active: true, |
| 18 |
source: source, |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
func (e *Entry) Enable() { |
| 24 |
e.active = true |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
func (e *Entry) Disable() { |
| 29 |
e.active = false |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
func (e Entry) Source() string { |
| 34 |
return e.source() |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
func Apply(callback func(Entry)) { |
| 39 |
for _, entry := range registry { |
| 40 |
if !entry.active { |
| 41 |
continue |
| 42 |
} |
| 43 |
callback(*entry) |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
func Register(source func() string) *Entry { |
| 49 |
entry := newEntry(source) |
| 50 |
registry = append(registry, entry) |
| 51 |
return entry |
| 52 |
} |