requestid

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: Apache-2.0 Imports: 3 Imported by: 26

README

RequestID (This is a community driven project)

Request ID middleware for Hertz framework, inspired by requestid. This project would not have been possible without the support from the CloudWeGo community and previous work done by the gin community.

  • Adds an identifier to the response using the X-Request-ID header.
  • Passes the X-Request-ID value back to the caller if it's sent in the request headers.

Install

go get github.com/hertz-contrib/requestid

Usage

usage description
default This is using requestid by default
custom key How to use requestid for custom key
custom generator How to use requestid for custom generator
custom handler How to use requestid for custom handler
get requestid How to get requestid
log with hertzlogrus How to log requestid with hertzlogrus

License

This project is under the Apache License 2.0. See the LICENSE file for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(c *app.RequestContext) string

Get returns the request identifier

func New

func New(opts ...Option) app.HandlerFunc

New initializes the RequestID middleware.

Types

type Generator

type Generator func(ctx context.Context, c *app.RequestContext) string

type Handler

type Handler func(ctx context.Context, c *app.RequestContext, requestID string)

type HeaderStrKey

type HeaderStrKey string

type Option

type Option func(*config)

Option for request id generator

func WithCustomHeaderStrKey

func WithCustomHeaderStrKey(s HeaderStrKey) Option

WithCustomHeaderStrKey set custom header key for request id

func WithGenerator

func WithGenerator(g Generator) Option

WithGenerator set generator function

func WithHandler

func WithHandler(handler Handler) Option

WithHandler set handler function for request id with context

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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