You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
388 B
Go
25 lines
388 B
Go
package wire
|
|
|
|
type Value interface {
|
|
NetTag() string
|
|
}
|
|
|
|
var registry = make(map[string]func() Value)
|
|
|
|
func Register(f func() Value) {
|
|
v := f()
|
|
t := v.NetTag()
|
|
if _, exists := registry[t]; exists {
|
|
panic("cannot register type: a type already exists with tag " + t)
|
|
}
|
|
registry[t] = f
|
|
}
|
|
|
|
func New(name string) Value {
|
|
f, ok := registry[name]
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return f()
|
|
}
|