initial commit

This commit is contained in:
ston1th 2021-09-26 17:53:47 +02:00
commit 8b15c38eab
8 changed files with 618 additions and 0 deletions

36
store.go Normal file
View 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
}