Commit c0f62e3f authored by Yong Tang's avatar Yong Tang Committed by GitHub

go lint cleanup (#891)

Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>
parent 26d8680a
...@@ -55,6 +55,9 @@ func (uh *UpstreamHost) Down() bool { ...@@ -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 { ...@@ -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() { ...@@ -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{}) { ...@@ -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 ( ...@@ -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)
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment