metadata

package
v0.0.0-...-488a668 Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package metadata allows to set/get additional context details from/on HTTP requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(options Options) func(http.Handler) http.Handler

Handler allows keeping HTTP headers or other request details as metadata in the context used when processing incoming requests. This allows other extensions and resolvers to have access to required information.

Upstream elements can retrieve available metadata with:

md, ok := FromContext(ctx)

Types

type MD

type MD = metadata.MD

MD provides a simple mechanism to propagate custom values through the context instance used while processing operations. Based on the gRPC implementation.

func FromContext

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

FromContext retrieves metadata information from the provided context if available.

type Options

type Options struct {
	// The headers must be specified in its lowercase (non-canonical) form.
	// If no specific headers are provided, all headers in the request are
	// registered as metadata by default.
	Headers []string `json:"headers" yaml:"headers" mapstructure:"headers"`

	// Provides complete flexibility to adjust the metadata produced for a
	// received request.
	Hook func(md *MD, r http.Request) `json:"-" yaml:"-" mapstructure:"-"`
}

Options available to adjust the behavior of the metadata middleware.

Jump to

Keyboard shortcuts

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