Skip to content

📚 Doc: Fix code snippet indentation in /docs/api/middleware/keyauth.md #2866

@grivera64

Description

@grivera64

Maintenance Task Description

The examples documentation for api/middleware/keyauth has an extra level of indentation in line 51.

package main

import (
    "crypto/sha256"
    "crypto/subtle"
    "github.com/gofiber/fiber/v2"
    "github.com/gofiber/fiber/v2/middleware/keyauth"
)

var (
    apiKey = "correct horse battery staple"
)

func validateAPIKey(c *fiber.Ctx, key string) (bool, error) {
    hashedAPIKey := sha256.Sum256([]byte(apiKey))
    hashedKey := sha256.Sum256([]byte(key))

    if subtle.ConstantTimeCompare(hashedAPIKey[:], hashedKey[:]) == 1 {
        return true, nil
    }
    return false, keyauth.ErrMissingOrMalformedAPIKey
}

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

    // note that the keyauth middleware needs to be defined before the routes are defined!
    app.Use(keyauth.New(keyauth.Config{
        KeyLookup:  "cookie:access_token",
        Validator:  validateAPIKey,
    }))

        app.Get("/", func(c *fiber.Ctx) error {
        return c.SendString("Successfully authenticated!")
    })

    app.Listen(":3000")
}

This typo is visible in both v2 and v3.

Impact on the Project

This is a minor indentation change in the documentation, but it will help improve the readability of the middleware/keyauth example.

Additional Context (optional)

v2 snippet
v3 snippet

I can make the fix and make a pull request, if that's okay.

Checklist:

  • I have confirmed that this maintenance task is currently not being addressed.
  • I understand that this task will be evaluated by the maintainers and prioritized accordingly.
  • I am available to provide further information if needed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions