Change store All to use channel
This commit is contained in:
@@ -9,6 +9,8 @@ import (
|
||||
"git.t-juice.club/torjus/apiary/models"
|
||||
)
|
||||
|
||||
var _ LoginAttemptStore = &MemoryStore{}
|
||||
|
||||
type MemoryStore struct {
|
||||
lock sync.RWMutex
|
||||
attempts []models.LoginAttempt
|
||||
@@ -32,8 +34,17 @@ func (ms *MemoryStore) AddAttempt(l *models.LoginAttempt) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ms *MemoryStore) All() ([]models.LoginAttempt, error) {
|
||||
return ms.attempts, nil
|
||||
func (ms *MemoryStore) All() (<-chan models.LoginAttempt, error) {
|
||||
ch := make(chan models.LoginAttempt)
|
||||
go func() {
|
||||
ms.lock.RLock()
|
||||
defer ms.lock.RUnlock()
|
||||
for _, attempt := range ms.attempts {
|
||||
ch <- attempt
|
||||
}
|
||||
close(ch)
|
||||
}()
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
func (ms *MemoryStore) Stats(statType LoginStats, limit int) ([]StatsResult, error) {
|
||||
|
Reference in New Issue
Block a user