middleware

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package middleware provides HTTP middleware for TxToken verification and propagation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClaimsFromContext

func ClaimsFromContext(ctx context.Context) *token.Claims

ClaimsFromContext extracts the verified TxToken claims from the request context. Returns nil if no claims are present (request was not verified).

func ExportedTokenContextKey

func ExportedTokenContextKey() contextKey

ExportedTokenContextKey returns the context key used for storing the TxToken. This is primarily useful for tests and advanced usage where direct context manipulation is needed.

func TokenFromContext

func TokenFromContext(ctx context.Context) string

TokenFromContext extracts the raw TxToken string from the request context. Returns an empty string if no token is present.

func VerifyTxToken

func VerifyTxToken(verifier *verify.Verifier) func(http.Handler) http.Handler

VerifyTxToken returns HTTP middleware that verifies the Txn-Token header on incoming requests. If valid, the claims are stored in the request context and the next handler is called. If invalid or missing, a 401 response is returned.

func WithToken

func WithToken(ctx context.Context, tokenString string) context.Context

WithToken stores a TxToken string in a context for propagation. Use this when a service obtains a TxToken (e.g., via the TTS client SDK) and needs to propagate it to downstream calls via PropagateTransport.

Types

type PropagateTransport

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

PropagateTransport is an http.RoundTripper that automatically propagates the Txn-Token header from the request context to outbound HTTP requests. Wrap your existing transport with NewPropagateTransport to enable propagation.

func NewPropagateTransport

func NewPropagateTransport(base http.RoundTripper) *PropagateTransport

NewPropagateTransport creates a new PropagateTransport wrapping the given base transport. If base is nil, http.DefaultTransport is used.

func (*PropagateTransport) RoundTrip

func (t *PropagateTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper. It copies the Txn-Token from the request's context into the outbound request header, then delegates to the base transport. If the header is already set on the request, it is not overwritten.

Jump to

Keyboard shortcuts

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