requestx

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package requestx provides the canonical request metadata model used by Kernel middleware. It is inspired by Kubernetes apiserver RequestInfo: every request is normalized once, then authn/authz/audit/ratelimit/log/metrics/trace stages read the same contract instead of each transport inventing its own metadata.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, info Info) context.Context

NewContext attaches Info to ctx.

func OperationKey

func OperationKey(ctx context.Context) string

OperationKey returns a stable operation/method key for rate limit, metrics and logs.

Types

type Direction

type Direction string

Direction identifies whether the request is entering this service or calling a downstream.

const (
	DirectionUnknown Direction = "unknown"
	DirectionServer  Direction = "server"
	DirectionClient  Direction = "client"
)

type Info

type Info struct {
	Direction Direction
	Protocol  Protocol

	Service   string
	Method    string
	Operation string
	Endpoint  string

	Exposure accessv1.Exposure
	Action   string
	Resource string

	TenantID  string
	RequestID string
	TraceID   string
	UserID    string

	CallerService string
	TargetService string

	IsSystem      bool
	IsInternal    bool
	IsLongRunning bool

	Labels map[string]string
}

Info is Kernel's normalized request metadata. Middleware should enrich and consume this value instead of re-parsing operation strings and headers.

func EnrichFromContext

func EnrichFromContext(ctx context.Context, info Info) Info

EnrichFromContext copies canonical contextx fields into info when missing.

func FromContext

func FromContext(ctx context.Context) (Info, bool)

FromContext returns Info from ctx.

func FromContextOr

func FromContextOr(ctx context.Context, fallback Info) Info

FromContextOr returns Info from ctx or fallback.

func FromTransport

func FromTransport(ctx context.Context, direction Direction) (Info, bool)

FromTransport builds base Info from transport context.

func (Info) Clone

func (i Info) Clone() Info

Clone returns a deep-enough copy safe for middleware enrichment.

func (Info) Merge

func (i Info) Merge(other Info) Info

Merge overlays non-zero fields from other onto i.

func (Info) Normalize

func (i Info) Normalize() Info

Normalize fills derived fields and safe defaults.

type Protocol

type Protocol string

Protocol identifies the inbound or outbound protocol.

const (
	ProtocolUnknown Protocol = "unknown"
	ProtocolHTTP    Protocol = "http"
	ProtocolGRPC    Protocol = "grpc"
)

type Resolver

type Resolver func(ctx context.Context, operation string, req any) (Info, bool, error)

Resolver maps ctx/operation/req into request metadata. Code generators should implement this from proto access policy. Runtime middleware can chain multiple resolvers.

Jump to

Keyboard shortcuts

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