requestid

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2020 License: MIT Imports: 3 Imported by: 4

README

Request ID

Release Discord Test Security Linter

Adds an indentifier to the response using the X-Request-ID header

Install
go get -u github.com/gofiber/fiber
go get -u github.com/gofiber/requestid
Signature
requestid.New(config ...requestid.Config) func(*fiber.Ctx)
Config
Property Type Description Default
Skip func(*fiber.Ctx) bool A function to skip the middleware nil
Generator func() string A function to generate an ID.e return uuid.New().String()
Example
package main

import (
  "github.com/gofiber/fiber"
  "github.com/gofiber/requestid"
)

func main() {
  app := fiber.New()
  
  app.Use(requestid.New())
  
  app.Get("/", func(c *fiber.Ctx) {
    c.Send(requestid.Get(c))
  })

  app.Listen(3000)
}
Test
curl -I http://localhost:3000

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(c *fiber.Ctx) string

Get returns the request identifier

func New

func New(config ...Config) func(*fiber.Ctx)

New adds an indentifier to the request

Types

type Config

type Config struct {
	// Filter defines a function to skip middleware.
	// Optional. Default: nil
	Filter func(*fiber.Ctx) bool
	// Generator defines a function to generate an ID.
	// Optional. Default: func() string {
	//   return uuid.New().String()
	// }
	Generator func() string
}

Config defines the config for RequestID middleware

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL