mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 00:34:24 -04:00
go lint cleanup (#891)
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@@ -55,6 +55,9 @@ func (uh *UpstreamHost) Down() bool {
|
|||||||
// HostPool is a collection of UpstreamHosts.
|
// HostPool is a collection of UpstreamHosts.
|
||||||
type HostPool []*UpstreamHost
|
type HostPool []*UpstreamHost
|
||||||
|
|
||||||
|
// HealthCheck is used for performing healthcheck
|
||||||
|
// on a collection of upstream hosts and select
|
||||||
|
// one based on the policy.
|
||||||
type HealthCheck struct {
|
type HealthCheck struct {
|
||||||
wg sync.WaitGroup // Used to wait for running goroutines to stop.
|
wg sync.WaitGroup // Used to wait for running goroutines to stop.
|
||||||
stop chan struct{} // Signals running goroutines to stop.
|
stop chan struct{} // Signals running goroutines to stop.
|
||||||
@@ -69,13 +72,14 @@ type HealthCheck struct {
|
|||||||
Interval time.Duration
|
Interval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start starts the healthcheck
|
||||||
func (u *HealthCheck) Start() {
|
func (u *HealthCheck) Start() {
|
||||||
u.stop = make(chan struct{})
|
u.stop = make(chan struct{})
|
||||||
if u.Path != "" {
|
if u.Path != "" {
|
||||||
u.wg.Add(1)
|
u.wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer u.wg.Done()
|
defer u.wg.Done()
|
||||||
u.HealthCheckWorker(u.stop)
|
u.healthCheckWorker(u.stop)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -178,7 +182,7 @@ func (u *HealthCheck) healthCheck() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *HealthCheck) HealthCheckWorker(stop chan struct{}) {
|
func (u *HealthCheck) healthCheckWorker(stop chan struct{}) {
|
||||||
ticker := time.NewTicker(u.Interval)
|
ticker := time.NewTicker(u.Interval)
|
||||||
u.healthCheck()
|
u.healthCheck()
|
||||||
for {
|
for {
|
||||||
@@ -192,6 +196,8 @@ func (u *HealthCheck) HealthCheckWorker(stop chan struct{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Select selects an upstream host based on the policy
|
||||||
|
// and the healthcheck result.
|
||||||
func (u *HealthCheck) Select() *UpstreamHost {
|
func (u *HealthCheck) Select() *UpstreamHost {
|
||||||
pool := u.Hosts
|
pool := u.Hosts
|
||||||
if len(pool) == 1 {
|
if len(pool) == 1 {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// SupportedPolicies is the collection of policies registered
|
||||||
SupportedPolicies = make(map[string]func() Policy)
|
SupportedPolicies = make(map[string]func() Policy)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user