...
1 package nodes
2
3 import (
4 "github.com/pkg/errors"
5 )
6
7 type BlockSet map[string]*Wrapper
8
9
10 func (bs BlockSet) Exists(name string) bool {
11 _, existing := bs[name]
12 return existing
13 }
14
15
16
17
18
19
20
21
22 func (bs *BlockSet) Register(name string, w *Wrapper) error {
23 if bs.Exists(name) {
24 return errors.Errorf("Block with name '%s' is already registered", name)
25 }
26 (*bs)[name] = w
27 return nil
28 }
29
30
31
32 func (bs *BlockSet) Replace(name string, w *Wrapper) error {
33 if !bs.Exists(name) {
34 return errors.Errorf("Block with name '%s' does not exist (therefore cannot be overridden)", name)
35 }
36 (*bs)[name] = w
37 return nil
38 }
39
View as plain text