requestid

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package requestid - the request's id: in its context, in the X-Request-Id response header and in the log lines written with the context (Handler), so a page's answer and its log lines can be matched.

Index

Constants

View Source
const Attr = "request_id"

Attr - the log field holding the id.

View Source
const Header = "X-Request-Id"

Header - the header carrying the id (a proxy in front may send its own).

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) string

FromContext - the id ctx carries, "" without one.

func New

func New() string

New - a fresh id: 16 hex digits.

func Valid

func Valid(s string) bool

Valid - whether s may be taken as an id from a proxy: 1 to 64 letters, digits, '-', '_' or '.' (it goes to the logs and a header as is).

func WithID

func WithID(ctx context.Context, id string) context.Context

WithID - ctx carrying the id.

Types

type Handler

type Handler struct {
	slog.Handler
}

Handler - a log handler adding request_id to the lines written with a request's context (logger.ErrorContext(r.Context(), …)).

func NewHandler

func NewHandler(h slog.Handler) *Handler

NewHandler wraps h.

func (*Handler) Handle

func (h *Handler) Handle(ctx context.Context, r slog.Record) error

Handle adds the context's id, if any.

func (*Handler) WithAttrs

func (h *Handler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs keeps the wrapper.

func (*Handler) WithGroup

func (h *Handler) WithGroup(name string) slog.Handler

WithGroup keeps the wrapper.

Jump to

Keyboard shortcuts

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