netalloc/store.go
2021-09-26 17:53:47 +02:00

36 lines
550 B
Go

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
}