dns: switch upstream when dial error occurred

This commit is contained in:
nadoo committed 2020-05-03 20:02:11 +08:00
1 parent 2fe9c3990b
commit 48e059db6c
5 files changed
+32 -19

No files matched your search

+8
View File
@@ -23,6 +23,14 @@ func (u *UpStream) Switch() string {
return u.servers[atomic.AddUint32(&u.index, 1)%uint32(len(u.servers))]
}
// SwitchIf switches to the next dns server if needed.
func (u *UpStream) SwitchIf(server string) string {
if u.Server() == server {
return u.Switch()
}
return u.Server()
}
// Len returns the number of dns servers.
func (u *UpStream) Len() int {
return len(u.servers)