Skip to content

Commit

Permalink
simple constructor for the untyped registers exposed
Browse files Browse the repository at this point in the history
  • Loading branch information
kpacha committed Apr 8, 2018
1 parent b4f454b commit 94033b2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
8 changes: 7 additions & 1 deletion register/internal/untyped_go19.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ package internal

import "sync"

func NewUntyped() *Untyped {
return &Untyped{
data: &sync.Map{},
}
}

type Untyped struct {
data sync.Map
data *sync.Map
}

func (u *Untyped) Register(name string, v interface{}) {
Expand Down
7 changes: 7 additions & 0 deletions register/internal/untyped_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ package internal

import "sync"

func NewUntyped() *Untyped {
return &Untyped{
data: map[string]interface{}{},
mutex: &sync.RWMutex{},
}
}

type Untyped struct {
data map[string]interface{}
mutex *sync.RWMutex
Expand Down
4 changes: 2 additions & 2 deletions register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ func (n *Namespaced) Register(namespace, name string, v interface{}) {
if r, ok := n.data[namespace]; ok {
r.Register(name, v)
} else {
n.data[namespace] = new(internal.Untyped)
n.data[namespace] = internal.NewUntyped()
n.data[namespace].Register(name, v)
}
n.mutex.Unlock()
}

func (n *Namespaced) AddNamespace(namespace string) {
n.mutex.Lock()
n.data[namespace] = new(internal.Untyped)
n.data[namespace] = internal.NewUntyped()
n.mutex.Unlock()
}

0 comments on commit 94033b2

Please sign in to comment.