chore: use atomictypes
Build / Build (push) Has been cancelled

This commit is contained in:
nadoo committed 2026-10-09 21:36:45 +08:00
1 parent 08bc767eda
commit 487da737b9
4 files changed
+31 -30

No files matched your search

+3 -3
View File
@@ -7,7 +7,7 @@ import (
// UPStream is a dns upstream.
type UPStream struct {
index uint32
index atomic.Uint32
servers []string
}
@@ -24,12 +24,12 @@ func NewUPStream(servers []string) *UPStream {
// Server returns a dns server.
func (u *UPStream) Server() string {
return u.servers[atomic.LoadUint32(&u.index)%uint32(len(u.servers))]
return u.servers[u.index.Load()%uint32(len(u.servers))]
}
// Switch switches to the next dns server.
func (u *UPStream) Switch() string {
return u.servers[atomic.AddUint32(&u.index, 1)%uint32(len(u.servers))]
return u.servers[u.index.Add(1)%uint32(len(u.servers))]
}
// SwitchIf switches to the next dns server if needed.