diff --git a/README.md b/README.md index b629db1..c9854f3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # apikey Simple API key validator middleware for [Fiber](https://github.com/gofiber/fiber). +**NOTE:** This repository only works with fiber/v2 + ## Install ``` @@ -14,7 +16,7 @@ package main import ( "github.com/gofiber/fiber" - "github.com/fiberweb/apikey" + "github.com/fiberweb/apikey/v2" ) func main() { diff --git a/apikey.go b/apikey.go index c72a989..382f6de 100644 --- a/apikey.go +++ b/apikey.go @@ -4,7 +4,7 @@ import ( "net/http" "os" - "github.com/gofiber/fiber" + "github.com/gofiber/fiber/v2" ) const ( @@ -50,7 +50,7 @@ var defaultConfig = Config{ } // New returns the middleware function -func New(config ...Config) func(*fiber.Ctx) { +func New(config ...Config) fiber.Handler { var cfg Config if len(config) == 0 { @@ -62,16 +62,14 @@ func New(config ...Config) func(*fiber.Ctx) { } } - return func(c *fiber.Ctx) { + return func(c *fiber.Ctx) error { if cfg.Skip != nil && cfg.Skip(c) { - c.Next() - return + return c.Next() } pass := cfg.ValidatorFunc(c, cfg) if !pass { - c.SendStatus(http.StatusUnauthorized) - return + return c.SendStatus(http.StatusUnauthorized) } - c.Next() + return c.Next() } }