diff options
author | 2017-08-10 18:00:23 -0700 | |
---|---|---|
committer | 2017-08-10 18:00:23 -0700 | |
commit | c0f62e3f65f891425e2a174c19112cfaa7fe1384 (patch) | |
tree | 3ec1d747f1f145825c60328a1aeadafbeb53332e | |
parent | 26d8680a11cbe444546d9ec247837ddf0594350e (diff) | |
download | coredns-c0f62e3f65f891425e2a174c19112cfaa7fe1384.tar.gz coredns-c0f62e3f65f891425e2a174c19112cfaa7fe1384.tar.zst coredns-c0f62e3f65f891425e2a174c19112cfaa7fe1384.zip |
go lint cleanup (#891)
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
-rw-r--r-- | middleware/pkg/healthcheck/healthcheck.go | 10 | ||||
-rw-r--r-- | middleware/pkg/healthcheck/policy.go | 1 |
2 files changed, 9 insertions, 2 deletions
diff --git a/middleware/pkg/healthcheck/healthcheck.go b/middleware/pkg/healthcheck/healthcheck.go index fc9f698e6..18f09087c 100644 --- a/middleware/pkg/healthcheck/healthcheck.go +++ b/middleware/pkg/healthcheck/healthcheck.go @@ -55,6 +55,9 @@ func (uh *UpstreamHost) Down() bool { // HostPool is a collection of UpstreamHosts. 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 { wg sync.WaitGroup // Used to wait for running goroutines to stop. stop chan struct{} // Signals running goroutines to stop. @@ -69,13 +72,14 @@ type HealthCheck struct { Interval time.Duration } +// Start starts the healthcheck func (u *HealthCheck) Start() { u.stop = make(chan struct{}) if u.Path != "" { u.wg.Add(1) go func() { 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) u.healthCheck() 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 { pool := u.Hosts if len(pool) == 1 { diff --git a/middleware/pkg/healthcheck/policy.go b/middleware/pkg/healthcheck/policy.go index 0cef8d79a..6a828fc4d 100644 --- a/middleware/pkg/healthcheck/policy.go +++ b/middleware/pkg/healthcheck/policy.go @@ -7,6 +7,7 @@ import ( ) var ( + // SupportedPolicies is the collection of policies registered SupportedPolicies = make(map[string]func() Policy) ) |