mirror of
https://github.com/pommee/goaway.git
synced 2026-01-11 16:40:32 -06:00
fix: fix cache issue with whitelisted domains
This commit is contained in:
@@ -18,12 +18,7 @@ func InitializeWhitelist(dbManager *database.DatabaseManager) (*Whitelist, error
|
||||
Cache: map[string]bool{},
|
||||
}
|
||||
|
||||
_, err := w.GetDomains()
|
||||
if err != nil {
|
||||
log.Error("Failed to initialize whitelist cache")
|
||||
}
|
||||
|
||||
return w, err
|
||||
return w, w.refreshCache()
|
||||
}
|
||||
|
||||
func (w *Whitelist) AddDomain(domain string) error {
|
||||
@@ -54,6 +49,23 @@ func (w *Whitelist) RemoveDomain(domain string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *Whitelist) refreshCache() error {
|
||||
for k := range w.Cache {
|
||||
delete(w.Cache, k)
|
||||
}
|
||||
|
||||
domains, err := w.GetDomains()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get whitelisted domains while refreshing cache, %v", err)
|
||||
}
|
||||
|
||||
for domain := range domains {
|
||||
w.Cache[domain] = true
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *Whitelist) GetDomains() (map[string]bool, error) {
|
||||
var records []database.Whitelist
|
||||
if err := w.DBManager.Conn.Find(&records).Error; err != nil {
|
||||
|
||||
Reference in New Issue
Block a user