Skip to content
This repository has been archived by the owner on Jul 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from danilabs/master
Browse files Browse the repository at this point in the history
Update to fiber/v2
  • Loading branch information
ekaputra07 authored Nov 23, 2020
2 parents cbeb2c2 + 6755fb3 commit 12b0fdd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

```
Expand All @@ -14,7 +16,7 @@ package main
import (
"github.com/gofiber/fiber"
"github.com/fiberweb/apikey"
"github.com/fiberweb/apikey/v2"
)
func main() {
Expand Down
14 changes: 6 additions & 8 deletions apikey.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"
"os"

"github.com/gofiber/fiber"
"github.com/gofiber/fiber/v2"
)

const (
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
}
}

0 comments on commit 12b0fdd

Please sign in to comment.