diff --git a/middleware/basic_auth.go b/middleware/basic_auth.go index 97c3ae9c..c1f34c8f 100644 --- a/middleware/basic_auth.go +++ b/middleware/basic_auth.go @@ -23,7 +23,7 @@ type ( } // BasicAuthValidator defines a function to validate BasicAuth credentials. - BasicAuthValidator func(string, string, echo.Context) (error, bool) + BasicAuthValidator func(string, string, echo.Context) (bool, error) ) const ( @@ -81,7 +81,7 @@ func BasicAuthWithConfig(config BasicAuthConfig) echo.MiddlewareFunc { for i := 0; i < len(cred); i++ { if cred[i] == ':' { // Verify credentials - err, valid := config.Validator(cred[:i], cred[i+1:], c) + valid, err := config.Validator(cred[:i], cred[i+1:], c) if err != nil { return err } else if valid { diff --git a/middleware/basic_auth_test.go b/middleware/basic_auth_test.go index 0e854e85..7a65b2a5 100644 --- a/middleware/basic_auth_test.go +++ b/middleware/basic_auth_test.go @@ -15,11 +15,11 @@ func TestBasicAuth(t *testing.T) { req := httptest.NewRequest(echo.GET, "/", nil) res := httptest.NewRecorder() c := e.NewContext(req, res) - f := func(u, p string, c echo.Context) (error, bool) { + f := func(u, p string, c echo.Context) (bool, error) { if u == "joe" && p == "secret" { - return nil, true + return true, nil } - return nil, false + return false, nil } h := BasicAuth(f)(func(c echo.Context) error { return c.String(http.StatusOK, "test") diff --git a/middleware/key_auth.go b/middleware/key_auth.go index 25189c95..5ef87e3d 100644 --- a/middleware/key_auth.go +++ b/middleware/key_auth.go @@ -32,7 +32,7 @@ type ( } // KeyAuthValidator defines a function to validate KeyAuth credentials. - KeyAuthValidator func(string, echo.Context) (error, bool) + KeyAuthValidator func(string, echo.Context) (bool, error) keyExtractor func(echo.Context) (string, error) ) @@ -94,7 +94,7 @@ func KeyAuthWithConfig(config KeyAuthConfig) echo.MiddlewareFunc { if err != nil { return echo.NewHTTPError(http.StatusBadRequest, err.Error()) } - err, valid := config.Validator(key, c) + valid, err := config.Validator(key, c) if err != nil { return err } else if valid { diff --git a/middleware/key_auth_test.go b/middleware/key_auth_test.go index edbe92f8..bf36006f 100644 --- a/middleware/key_auth_test.go +++ b/middleware/key_auth_test.go @@ -15,8 +15,8 @@ func TestKeyAuth(t *testing.T) { res := httptest.NewRecorder() c := e.NewContext(req, res) config := KeyAuthConfig{ - Validator: func(key string, c echo.Context) (error, bool) { - return nil, key == "valid-key" + Validator: func(key string, c echo.Context) (bool, error) { + return key == "valid-key", nil }, } h := KeyAuthWithConfig(config)(func(c echo.Context) error {