Skip to content

v0.2.0

Choose a tag to compare

@github-actions github-actions released this 10 Mar 11:09
· 1 commit to main since this release

feat:

  • optional structured error message (45beb0)

Usage

package main

import (
  "os"

  "github.com/iwpnd/fiber-key-auth"
  "github.com/gofiber/fiber/v2"
)

os.Setenv("API_KEY_TEST", "valid")

func main() {
    app := fiber.New()

    app.Use(keyauth.New(WithStructuredErrorMsg()))

    app.Get("/", func(c *fiber.Ctx) error {
        return c.SendString("Hello, World 👋!")
    })

    app.Listen(":3000")
}
curl localhost:3000

>> {"message": "no api key"}

curl localhost:3000 -H "x-api-key: invalid"

>> {"message": "invalid api key"}

curl localhost:3000 -H "x-api-key: valid"

>> "Hello, World 👋!"