forked from luraproject/lura
-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.go
50 lines (41 loc) · 953 Bytes
/
register.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
40
41
42
43
44
45
46
47
48
49
50
package register
import (
"github.com/podliy16/krakend/register/internal"
)
func New() *Namespaced {
return &Namespaced{NewUntyped()}
}
type Namespaced struct {
data Untyped
}
func (n *Namespaced) Get(namespace string) (Untyped, bool) {
v, ok := n.data.Get(namespace)
if !ok {
return nil, ok
}
register, ok := v.(Untyped)
return register, ok
}
func (n *Namespaced) Register(namespace, name string, v interface{}) {
if register, ok := n.Get(namespace); ok {
register.Register(name, v)
return
}
register := NewUntyped()
register.Register(name, v)
n.data.Register(namespace, register)
}
func (n *Namespaced) AddNamespace(namespace string) {
if _, ok := n.Get(namespace); ok {
return
}
n.data.Register(namespace, NewUntyped())
}
type Untyped interface {
Register(name string, v interface{})
Get(name string) (interface{}, bool)
Clone() map[string]interface{}
}
func NewUntyped() Untyped {
return internal.NewUntyped()
}