diff --git a/main.go b/main.go index 5ac4598..feef580 100644 --- a/main.go +++ b/main.go @@ -34,6 +34,7 @@ type URLSelector struct { URLs []string CurrentIndex int RecentUsed map[string]int + mu sync.Mutex } func NewURLSelector(urls []string) *URLSelector { @@ -52,6 +53,9 @@ func (us *URLSelector) ShuffleURLs() { } func (us *URLSelector) GetRandomURL() string { + us.mu.Lock() + defer us.mu.Unlock() + if us.CurrentIndex == 0 { us.ShuffleURLs() }