summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-12-14 15:30:55 -0700
committerMatthew Holt <mholt@users.noreply.github.com>2020-12-14 15:30:55 -0700
commit132525de3bfd6acb16f8628fa057cb03e102a177 (patch)
treee0609c7612cc7e0c306cf282deaa93ac9f38ba92
parentdeedf8abb036bdc096360bd6f06df17a6cff9799 (diff)
reverseproxy: Minor lint fixes
-rw-r--r--modules/caddyhttp/reverseproxy/selectionpolicies.go21
-rw-r--r--modules/caddyhttp/reverseproxy/selectionpolicies_test.go10
2 files changed, 15 insertions, 16 deletions
diff --git a/modules/caddyhttp/reverseproxy/selectionpolicies.go b/modules/caddyhttp/reverseproxy/selectionpolicies.go
index a391b2f..e86e97e 100644
--- a/modules/caddyhttp/reverseproxy/selectionpolicies.go
+++ b/modules/caddyhttp/reverseproxy/selectionpolicies.go
@@ -401,17 +401,16 @@ func (s CookieHashSelection) Select(pool UpstreamPool, req *http.Request, w http
// If there's no cookie, select new random host
if err != nil || cookie == nil {
return selectNewHostWithCookieHashSelection(pool, w, s.Secret, s.Name)
- } else {
- // If the cookie is present, loop over the available upstreams until we find a match
- cookieValue := cookie.Value
- for _, upstream := range pool {
- if !upstream.Available() {
- continue
- }
- sha, err := hashCookie(s.Secret, upstream.Dial)
- if err == nil && sha == cookieValue {
- return upstream
- }
+ }
+ // If the cookie is present, loop over the available upstreams until we find a match
+ cookieValue := cookie.Value
+ for _, upstream := range pool {
+ if !upstream.Available() {
+ continue
+ }
+ sha, err := hashCookie(s.Secret, upstream.Dial)
+ if err == nil && sha == cookieValue {
+ return upstream
}
}
// If there is no matching host, select new random host
diff --git a/modules/caddyhttp/reverseproxy/selectionpolicies_test.go b/modules/caddyhttp/reverseproxy/selectionpolicies_test.go
index 5368a1a..70d05ac 100644
--- a/modules/caddyhttp/reverseproxy/selectionpolicies_test.go
+++ b/modules/caddyhttp/reverseproxy/selectionpolicies_test.go
@@ -335,11 +335,11 @@ func TestCookieHashPolicy(t *testing.T) {
w := httptest.NewRecorder()
cookieHashPolicy := new(CookieHashSelection)
h := cookieHashPolicy.Select(pool, request, w)
- cookie_server1 := w.Result().Cookies()[0]
- if cookie_server1 == nil {
+ cookieServer1 := w.Result().Cookies()[0]
+ if cookieServer1 == nil {
t.Error("cookieHashPolicy should set a cookie")
}
- if cookie_server1.Name != "lb" {
+ if cookieServer1.Name != "lb" {
t.Error("cookieHashPolicy should set a cookie with name lb")
}
if h != pool[0] {
@@ -349,7 +349,7 @@ func TestCookieHashPolicy(t *testing.T) {
pool[2].SetHealthy(true)
request = httptest.NewRequest(http.MethodGet, "/test", nil)
w = httptest.NewRecorder()
- request.AddCookie(cookie_server1)
+ request.AddCookie(cookieServer1)
h = cookieHashPolicy.Select(pool, request, w)
if h != pool[0] {
t.Error("Expected cookieHashPolicy host to stick to the first host (matching cookie).")
@@ -361,7 +361,7 @@ func TestCookieHashPolicy(t *testing.T) {
pool[0].SetHealthy(false)
request = httptest.NewRequest(http.MethodGet, "/test", nil)
w = httptest.NewRecorder()
- request.AddCookie(cookie_server1)
+ request.AddCookie(cookieServer1)
h = cookieHashPolicy.Select(pool, request, w)
if h == pool[0] {
t.Error("Expected cookieHashPolicy to select a new host.")