initial commit
This commit is contained in:
commit
8b15c38eab
8 changed files with 618 additions and 0 deletions
36
store.go
Normal file
36
store.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package netalloc
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Store interface {
|
||||
sync.Locker
|
||||
Exists(key string) (bool, error)
|
||||
Add(key string) error
|
||||
Delete(key string) error
|
||||
}
|
||||
|
||||
type MemStore struct {
|
||||
sync.Mutex
|
||||
m map[string]struct{}
|
||||
}
|
||||
|
||||
func NewMemStore() Store {
|
||||
return &MemStore{m: make(map[string]struct{})}
|
||||
}
|
||||
|
||||
func (m *MemStore) Exists(key string) (bool, error) {
|
||||
_, ok := m.m[key]
|
||||
return ok, nil
|
||||
}
|
||||
|
||||
func (m *MemStore) Add(key string) error {
|
||||
m.m[key] = struct{}{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MemStore) Delete(key string) error {
|
||||
delete(m.m, key)
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue