xrequestid

package
v0.0.0-...-4e7bad8 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: MIT Imports: 5 Imported by: 0

README

X-Request-ID

This package provides a functional for requests tagging with a unique ID. Here is a few examples of usage:

gRPC
server = grpc.NewServer(
    grpc.InTapHandle(xrequestid.New().InTapHandler),
)

if you don't want to use InTapHandle you can use UnaryInterceptor:

server = grpc.NewServer(
    grpc.UnaryInterceptor(xrequestid.New().UnaryInterceptor),
) 
HTTP
server := &http.Server{
    Handler: xrequestid.New().PopulateHTTP(http.DefaultServeMux),
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Populate

func Populate(parent context.Context, xid XRequestID) context.Context

Types

type Generator

type Generator interface {
	Generate() XRequestID
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Handler

func (*Handler) InTapHandler

func (h *Handler) InTapHandler(ctx context.Context, _ *tap.Info) (context.Context, error)

func (*Handler) PopulateHTTP

func (h *Handler) PopulateHTTP(next http.Handler) http.Handler

func (*Handler) UnaryInterceptor

func (h *Handler) UnaryInterceptor(
	ctx context.Context,
	req any,
	_ *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

type Option

type Option func(*Handler)

func WithGenerator

func WithGenerator(gen Generator) Option

func WithHeaderHTTP

func WithHeaderHTTP(header string) Option

type ShortuuidGenerator

type ShortuuidGenerator struct{}

func (ShortuuidGenerator) Generate

func (ShortuuidGenerator) Generate() XRequestID

type XRequestID

type XRequestID = string

func Get

func Get(ctx context.Context) (xid XRequestID, ok bool)

Jump to

Keyboard shortcuts

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