requestid

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: MIT Imports: 2 Imported by: 0

README

requestid

The Lightning Request ID middleware is designed to provide unique request IDs for every incoming request and add them to logs and response headers. This helps with tracking request in a distributed system, making it easier to debug and troubleshoot issues.

Installation

To use the Request ID middleware, you can install it using the following command:

go get github.com/lightning-contrib/requestid

Usage

Here is an example of how to use requestid middleware:

package main

import (
	"github.com/go-labx/lightning"
	"github.com/lightning-contrib/requestid"
)

func main() {
	app := lightning.NewApp()
	app.Use(requestid.Default())

	app.Get("/ping", func(ctx *lightning.Context) {
		ctx.JSON(200, map[string]string{
			"message": "pong",
		})
	})

	app.Run()
}

You can also use the New() function, it also returns a middleware, but it allows for customization of the config struct through the use of variadic Options arguments.

app.Use(requestid.New(
    requestid.WithAlphabet("1234567890"),
    requestid.WithHeaderKey("X-Custom-ID"),
    requestid.WithSize(16)),
)

API Documentation

For detailed API documentation and usage examples, please refer to the documentation.

Contributing

If you'd like to contribute to lightning, please see CONTRIBUTING.md for guidelines.

License

lightning is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Default

func Default() lightning.Middleware

func New

func New(options ...Options) lightning.Middleware

Types

type Options

type Options func(*config)

func WithAlphabet

func WithAlphabet(alphabet string) Options

func WithHeaderKey

func WithHeaderKey(key string) Options

func WithSize

func WithSize(size int) Options

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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