From c4bb234c2c2371e6ac3866288a65aab4ee93bf8d Mon Sep 17 00:00:00 2001 From: wood chen Date: Sun, 13 Oct 2024 18:17:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=92=E6=96=A5=E9=94=81?= =?UTF-8?q?=E4=BB=A5=E4=BF=9D=E6=8A=A4URLSelector=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E4=BD=93=E7=9A=84=E5=B9=B6=E5=8F=91=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 4 ++++ 1 file changed, 4 insertions(+) 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() }