reqctx

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package reqctx implements helpers around http.Handler.Context.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get[T any](ctx context.Context, k *Key[T]) (v T, ok bool)

Get returns the value stored under k in ctx, and whether it was present. A present-but-zero-value entry reports ok == true.

func Set

func Set[T any](ctx context.Context, k *Key[T], v T) context.Context

Set returns ctx with v stored under k.

func WithValue

func WithValue[T any](r *http.Request, k *Key[T], v T) *http.Request

WithValue returns r with v stored under k in r.Context.

Types

type Key

type Key[T any] struct{}

Key represents a typed, collision-safe context key for values of type T. The zero value of Key is not meant to be used directly.

func NewKey

func NewKey[T any]() *Key[T]

NewKey creates a new context key for values of type T.

Jump to

Keyboard shortcuts

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