mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
dns: allow to switch dns server permanently (#97)
This commit is contained in:
1 parent
b99a730968
commit
a9a1985a4b
5 files changed
+55
-19
No files matched your search
@@ -0,0 +1,29 @@
|
||||
package dns
|
||||
|
||||
import "sync/atomic"
|
||||
|
||||
// UpStream is a dns upstream.
|
||||
type UpStream struct {
|
||||
index uint32
|
||||
servers []string
|
||||
}
|
||||
|
||||
// NewUpStream returns a new UpStream.
|
||||
func NewUpStream(servers []string) *UpStream {
|
||||
return &UpStream{servers: servers}
|
||||
}
|
||||
|
||||
// Server returns a dns server.
|
||||
func (u *UpStream) Server() string {
|
||||
return u.servers[atomic.LoadUint32(&u.index)%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))]
|
||||
}
|
||||
|
||||
// Len returns the number of dns servers.
|
||||
func (u *UpStream) Len() int {
|
||||
return len(u.servers)
|
||||
}
|
||||
Reference in new issue
Block a user