mirror of
https://github.com/coredns/coredns.git
synced 2025-11-19 18:32:16 -05:00
Plugin/Proxy - add new policy always_first to mimic windows dns resolvers (#1459)
* add new policy always_first to mimic windows dns resolvers fill documentation, add UT and cleanup fmt * change name of policy from always_first to first. Update docs
This commit is contained in:
committed by
John Belamaric
parent
0af9b9b16f
commit
b93a36b213
@@ -27,6 +27,7 @@ func init() {
|
||||
RegisterPolicy("random", func() Policy { return &Random{} })
|
||||
RegisterPolicy("least_conn", func() Policy { return &LeastConn{} })
|
||||
RegisterPolicy("round_robin", func() Policy { return &RoundRobin{} })
|
||||
RegisterPolicy("first", func() Policy { return &First{} })
|
||||
}
|
||||
|
||||
// Random is a policy that selects up hosts from a pool at random.
|
||||
@@ -118,3 +119,19 @@ func (r *RoundRobin) Select(pool HostPool) *UpstreamHost {
|
||||
}
|
||||
return host
|
||||
}
|
||||
|
||||
// First is a policy that selects always the first healthy host in the list order.
|
||||
type First struct{}
|
||||
|
||||
// Select always the first that is not Down.
|
||||
func (r *First) Select(pool HostPool) *UpstreamHost {
|
||||
for i := 0; i < len(pool); i++ {
|
||||
host := pool[i]
|
||||
if host.Down() {
|
||||
continue
|
||||
}
|
||||
return host
|
||||
}
|
||||
// return the first one, anyway none is correct
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user