diff --git a/storage/ram.go b/storage/ram.go index 6ff4dc9..87ba129 100644 --- a/storage/ram.go +++ b/storage/ram.go @@ -6,11 +6,12 @@ import ( "time" ) -func NewRamStore() Store { +func NewRamStore(clearInterval time.Duration) Store { store := &ram{ - passwords: make(map[string]entry), - lock: sync.Mutex{}, - close: make(chan bool), + clearInterval: clearInterval, + passwords: make(map[string]entry), + lock: sync.Mutex{}, + close: make(chan bool), } go store.clearExpired() @@ -18,9 +19,10 @@ func NewRamStore() Store { } type ram struct { - passwords map[string]entry - lock sync.Mutex - close chan bool + clearInterval time.Duration + passwords map[string]entry + lock sync.Mutex + close chan bool } func (store *ram) CreatePassword(password []byte, expiresAt time.Time) (string, error) { @@ -64,7 +66,7 @@ func (store *ram) Close() error { } func (store *ram) clearExpired() error { - ticker := time.NewTicker(20 * time.Second) + ticker := time.NewTicker(store.clearInterval) defer ticker.Stop() for { diff --git a/storage/storage.go b/storage/storage.go index 8151500..3d7dac1 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -30,10 +30,10 @@ func NewStore() (Store, error) { switch storeType { case "ram": - return NewRamStore(), nil + return NewRamStore(20 * time.Second), nil default: log.Printf("No PASSED_STORE_TYPE provided, defaulting to memory store.") - return NewRamStore(), nil + return NewRamStore(20 * time.Second), nil } }