Change store All to use channel
This commit is contained in:
@@ -2,6 +2,8 @@ package store
|
||||
|
||||
import "git.t-juice.club/torjus/apiary/models"
|
||||
|
||||
var _ LoginAttemptStore = &CachingStore{}
|
||||
|
||||
type CachingStore struct {
|
||||
backend LoginAttemptStore
|
||||
|
||||
@@ -33,14 +35,16 @@ func NewCachingStore(backend LoginAttemptStore) *CachingStore {
|
||||
//TODO: Handle better maybe?
|
||||
panic(err)
|
||||
}
|
||||
var loginCount int
|
||||
|
||||
cs.totalLoginsCount = len(all)
|
||||
for _, attempt := range all {
|
||||
for attempt := range all {
|
||||
cs.uniqueUsernames[attempt.Username] = struct{}{}
|
||||
cs.uniquePasswords[attempt.Password] = struct{}{}
|
||||
cs.uniqueIPs[attempt.RemoteIP.String()] = struct{}{}
|
||||
cs.uniqueCountries[attempt.Country] = struct{}{}
|
||||
loginCount++
|
||||
}
|
||||
cs.totalLoginsCount = loginCount
|
||||
|
||||
return cs
|
||||
}
|
||||
@@ -58,7 +62,7 @@ func (s *CachingStore) AddAttempt(l *models.LoginAttempt) error {
|
||||
return s.backend.AddAttempt(l)
|
||||
}
|
||||
|
||||
func (s *CachingStore) All() ([]models.LoginAttempt, error) {
|
||||
func (s *CachingStore) All() (<-chan models.LoginAttempt, error) {
|
||||
return s.backend.All()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user