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

Update to fiber/v2 #1

Merged
merged 1 commit into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}