Skip to content

Commit

Permalink
teardown code and cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Lee <dave@gray101.com>
  • Loading branch information
dave-gray101 committed Jun 10, 2024
1 parent 397ff49 commit 2968439
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions middleware/keyauth/keyauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func SingleKeyLookup(keyLookup, authScheme string) (KeyauthKeyLookupFunc, error)
}

// keyFromHeader returns a function that extracts api key from the request header.
func keyFromHeader(header, authScheme string) func(c fiber.Ctx) (string, error) {
func keyFromHeader(header, authScheme string) KeyauthKeyLookupFunc {
return func(c fiber.Ctx) (string, error) {
auth := c.Get(header)
l := len(authScheme)
Expand All @@ -136,7 +136,7 @@ func keyFromHeader(header, authScheme string) func(c fiber.Ctx) (string, error)
}

// keyFromQuery returns a function that extracts api key from the query string.
func keyFromQuery(param string) func(c fiber.Ctx) (string, error) {
func keyFromQuery(param string) KeyauthKeyLookupFunc {
return func(c fiber.Ctx) (string, error) {
key := fiber.Query[string](c, param)
if key == "" {
Expand All @@ -147,7 +147,7 @@ func keyFromQuery(param string) func(c fiber.Ctx) (string, error) {
}

// keyFromForm returns a function that extracts api key from the form.
func keyFromForm(param string) func(c fiber.Ctx) (string, error) {
func keyFromForm(param string) KeyauthKeyLookupFunc {
return func(c fiber.Ctx) (string, error) {
key := c.FormValue(param)
if key == "" {
Expand All @@ -158,7 +158,7 @@ func keyFromForm(param string) func(c fiber.Ctx) (string, error) {
}

// keyFromParam returns a function that extracts api key from the url param string.
func keyFromParam(param string) func(c fiber.Ctx) (string, error) {
func keyFromParam(param string) KeyauthKeyLookupFunc {
return func(c fiber.Ctx) (string, error) {
key, err := url.PathUnescape(c.Params(param))
if err != nil {
Expand All @@ -169,7 +169,7 @@ func keyFromParam(param string) func(c fiber.Ctx) (string, error) {
}

// keyFromCookie returns a function that extracts api key from the named cookie.
func keyFromCookie(name string) func(c fiber.Ctx) (string, error) {
func keyFromCookie(name string) KeyauthKeyLookupFunc {
return func(c fiber.Ctx) (string, error) {
key := c.Cookies(name)
if key == "" {
Expand Down
1 change: 1 addition & 0 deletions middleware/keyauth/keyauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func TestPanicOnInvalidConfiguration(t *testing.T) {
})
// We shouldn't even make it this far, but these next two lines prevent authMiddleware from being an unused variable.
app := fiber.New()
defer app.Shutdown()
app.Use(authMiddleware)
})
}
Expand Down

0 comments on commit 2968439

Please sign in to comment.