Debian Codegraph @

registry/registry.go

raw symbols SCIP
1 // Package registry is an experimental package to facilitate altering the otto runtime via import.
2 //
3 // This interface can change at any time.
4 package registry
5
6 var registry []*Entry = make([]*Entry, 0)
7
8 // Entry represents a registry entry.
9 type Entry struct {
10 source func() string
11 active bool
12 }
13
14 // newEntry returns a new Entry for source.
15 func newEntry(source func() string) *Entry {
16 return &Entry{
17 active: true,
18 source: source,
19 }
20 }
21
22 // Enable enables the entry.
23 func (e *Entry) Enable() {
24 e.active = true
25 }
26
27 // Disable disables the entry.
28 func (e *Entry) Disable() {
29 e.active = false
30 }
31
32 // Source returns the source of the entry.
33 func (e Entry) Source() string {
34 return e.source()
35 }
36
37 // Apply applies callback to all registry entries.
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 // Register registers a new Entry for source.
48 func Register(source func() string) *Entry {
49 entry := newEntry(source)
50 registry = append(registry, entry)
51 return entry
52 }