appctx

package
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCookies

func AddCookies(ctx context.Context, cookies []*http.Cookie)

AddCookies appends cookies to the HTTP response metadata in context.

func GetAPIVersionFromContext

func GetAPIVersionFromContext(ctx context.Context) (version.APIVersion, bool)

GetAPIVersionFromContext retrieves the API version from the context.

func GetAllowedMethods

func GetAllowedMethods(ctx context.Context) ([]string, bool)

GetAllowedMethods retrieves the allowed methods from the context.

func GetExternalHost

func GetExternalHost(ctx context.Context) (string, bool)

GetExternalHost retrieves the external request host stored in the context.

func GetHandler

func GetHandler(ctx context.Context) (string, bool)

GetHandler retrieves the handler name from the context.

func GetIdempotencyKey

func GetIdempotencyKey(ctx context.Context) (string, bool)

GetIdempotencyKey retrieves the idempotency key from the context.

func GetIdempotencyKeyID

func GetIdempotencyKeyID(ctx context.Context) (string, bool)

GetIdempotencyKeyID retrieves the idempotency key ID from the context.

func GetIdentityFromContext

func GetIdentityFromContext(ctx context.Context) (*types.Identity, bool)

GetIdentityFromContext retrieves the identity from the context.

func GetPathParams

func GetPathParams(ctx context.Context) (map[string]string, bool)

GetPathParams retrieves the path parameters from the context.

func GetPlatformFromContext

func GetPlatformFromContext(ctx context.Context) (constants.PlatformMode, bool)

GetPlatformFromContext retrieves the platform mode from the context.

func GetPropagatedClientIP

func GetPropagatedClientIP(ctx context.Context) (string, bool)

GetPropagatedClientIP returns the client IP from WithPropagatedClientIP when present and non-empty.

func GetRequestID

func GetRequestID(ctx context.Context) (string, bool)

GetRequestID retrieves the request ID from the context.

func GetRequestURL

func GetRequestURL(ctx context.Context) (*url.URL, bool)

GetRequestURL retrieves the request URL stored in the context.

func GetRoutePattern

func GetRoutePattern(ctx context.Context) (string, bool)

GetRoutePattern retrieves the route pattern from the context.

func MarkIdempotencyReplayed

func MarkIdempotencyReplayed(ctx context.Context)

MarkIdempotencyReplayed sets the Replayed flag on the context's idempotency response metadata. Safe to call when no metadata is present.

func SetHTTPReplayed

func SetHTTPReplayed(ctx context.Context, replayed bool)

SetHTTPReplayed sets the Replayed flag on the HTTP response metadata in context.

func ShouldTrace

func ShouldTrace(ctx context.Context) bool

ShouldTrace returns true if tracing has NOT been suppressed on ctx via WithNoTrace.

func WithAPIVersion

func WithAPIVersion(ctx context.Context, v version.APIVersion) context.Context

WithAPIVersion returns a child context carrying the given API version.

func WithAllowedMethods

func WithAllowedMethods(ctx context.Context, methods []string) context.Context

WithAllowedMethods returns a child context carrying the allowed HTTP methods.

func WithExternalHost

func WithExternalHost(ctx context.Context, host string) context.Context

WithExternalHost returns a child context carrying the host the browser addressed (from X-Forwarded-Host when the request arrived through a trusted front proxy such as the frontend's custom-domain API rewrite, otherwise the Host header). Auth cookie scoping keys off this value.

func WithHandler

func WithHandler(ctx context.Context, method string) context.Context

WithHandler returns a child context carrying the given handler name.

func WithIdempotencyKey

func WithIdempotencyKey(ctx context.Context, key string) context.Context

WithIdempotencyKey returns a child context carrying the client-supplied idempotency key.

func WithIdempotencyKeyID

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

WithIdempotencyKeyID returns a child context carrying the idempotency key database ID.

func WithIdempotencyResponseMetadata

func WithIdempotencyResponseMetadata(ctx context.Context, meta *IdempotencyResponseMetadata) context.Context

WithIdempotencyResponseMetadata returns a child context carrying the given metadata pointer.

func WithIdentity

func WithIdentity(ctx context.Context, identity *types.Identity) context.Context

WithIdentity returns a child context carrying the given identity.

func WithNoTrace

func WithNoTrace(ctx context.Context) context.Context

WithNoTrace returns a derived context that suppresses span creation for the current call tree.

func WithPathParams

func WithPathParams(ctx context.Context, params map[string]string) context.Context

WithPathParams returns a child context carrying the path parameters.

func WithPlatform

func WithPlatform(ctx context.Context, platform constants.PlatformMode) context.Context

WithPlatform returns a child context carrying the given platform mode.

func WithPropagatedClientIP

func WithPropagatedClientIP(ctx context.Context, ip string) context.Context

WithPropagatedClientIP attaches the original HTTP client IP when it was forwarded from the API gateway via gRPC metadata.

func WithRequestID

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

WithRequestID returns a child context carrying the platform-generated request ID.

func WithRequestLog

func WithRequestLog(ctx context.Context, rl *RequestLog) context.Context

WithRequestLog returns a child context carrying the request log.

func WithRequestURL

func WithRequestURL(ctx context.Context, u *url.URL) context.Context

WithRequestURL returns a child context carrying the current HTTP request URL. This is used by list presenters to build absolute pagination URLs.

func WithRoutePattern

func WithRoutePattern(ctx context.Context, pattern string) context.Context

WithRoutePattern returns a child context carrying the matched route pattern.

Types

type HTTPResponseMetadata

type HTTPResponseMetadata struct {
	Cookies  []*http.Cookie
	Replayed bool
}

HTTPResponseMetadata carries response-scoped data (cookies, replay flag) through the request lifecycle via a shared pointer in context.

func GetHTTPResponseMetadata

func GetHTTPResponseMetadata(ctx context.Context) (*HTTPResponseMetadata, bool)

GetHTTPResponseMetadata retrieves the HTTP response metadata from the context.

func WithHTTPResponseMetadata

func WithHTTPResponseMetadata(ctx context.Context) (context.Context, *HTTPResponseMetadata)

WithHTTPResponseMetadata returns a child context carrying a fresh metadata pointer. The pointer is shared so downstream code can mutate it.

type IdempotencyResponseMetadata

type IdempotencyResponseMetadata struct {
	Replayed bool
}

IdempotencyResponseMetadata holds mutable, response-scoped flags that allow service-layer code to communicate information back to the transport layer.

func GetIdempotencyResponseMetadata

func GetIdempotencyResponseMetadata(ctx context.Context) (*IdempotencyResponseMetadata, bool)

GetIdempotencyResponseMetadata retrieves the metadata pointer from the context.

type RequestLog

type RequestLog struct {
	ID                      string          `json:"id"`
	Method                  string          `json:"method"`
	Host                    string          `json:"host"`
	Path                    string          `json:"path"`
	NormalizedRoute         string          `json:"normalized_route"`
	QueryJSON               *string         `json:"query_json,omitempty"`
	StatusCode              int             `json:"status_code"`
	LatencyUs               int64           `json:"latency_us"`
	AccountID               *string         `json:"account_id,omitempty"`
	TargetAccountID         *string         `json:"target_account_id,omitempty"`
	ActorID                 *string         `json:"actor_id,omitempty"`
	ActorType               *string         `json:"actor_type"`
	IdentityType            *string         `json:"identity_type"`
	ClientIP                []byte          `json:"client_ip"`
	ClientIPString          *string         `json:"client_ip_string"`
	UserAgent               *string         `json:"user_agent"`
	Referrer                *string         `json:"referrer,omitempty"`
	ErrorCode               *string         `json:"error_code,omitempty"`
	ErrorMessage            *string         `json:"error_message,omitempty"`
	OccurredAt              time.Time       `json:"occurred_at"`
	IdempotencyKeyID        *string         `json:"idempotency_key_id"`
	InternalErrorMessage    *string         `json:"internal_error_message,omitempty"`
	StackTrace              *string         `json:"stack_trace,omitempty"`
	APIVersion              *string         `json:"api_version,omitempty"`
	TraceID                 *string         `json:"trace_id,omitempty"`
	PublicEndpoint          bool            `json:"public_endpoint"`
	BodyJSON                *string         `json:"body_json,omitempty"`
	ResponseJSON            *string         `json:"response_json,omitempty"`
	SkipSave                bool            `json:"-"`
	Hidden                  bool            `json:"-"` // persisted but omitted from the default request-log listing; set from the endpoint's HideFromRequestLog flag
	SensitiveResponseFields map[string]bool `json:"-"`
}

RequestLog captures metadata about an HTTP request for logging and auditing.

func GetRequestLog

func GetRequestLog(ctx context.Context) (*RequestLog, bool)

GetRequestLog retrieves the request log from the context.

Jump to

Keyboard shortcuts

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