context

package
v0.0.0-...-d2bd8cc Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2020 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const MetadataHeaderPrefix = "Grpc-Metadata-"

MetadataHeaderPrefix is the http prefix that represents custom metadata parameters to or from a gRPC call.

View Source
const MetadataPrefix = "pbgo-grpc-"

MetadataPrefix is prepended to permanent HTTP header keys (as specified by the IANA) when added to the gRPC context.

View Source
const MetadataTrailerPrefix = "Grpc-Trailer-"

MetadataTrailerPrefix is prepended to gRPC metadata as it is converted to HTTP headers in a response handled by pbgo-grpc

Variables

View Source
var (
	// DefaultContextTimeout is used for gRPC call context.WithTimeout whenever a Grpc-Timeout inbound
	// header isn't present. If the value is 0 the sent `context` will not have a timeout.
	DefaultContextTimeout = 0 * time.Second
)

Functions

func AnnotateIncomingContext

func AnnotateIncomingContext(
	ctx context.Context, req *http.Request,
	incomingHeaderMatcher HeaderMatcherFunc,
	metadataAnnotators ...func(context.Context, *http.Request) metadata.MD,
) (context.Context, error)

AnnotateIncomingContext adds context information such as metadata from the request.

At a minimum, the RemoteAddr is included in the fashion of "X-Forwarded-For", except that the forwarded destination is not another HTTP service but rather a gRPC service.

func AnnotateOutgoingContext

func AnnotateOutgoingContext(
	ctx context.Context, req *http.Request,
	incomingHeaderMatcher HeaderMatcherFunc,
	metadataAnnotators ...func(context.Context, *http.Request) metadata.MD,
) (context.Context, error)

AnnotateOutgoingContext adds context information such as metadata from the request.

At a minimum, the RemoteAddr is included in the fashion of "X-Forwarded-For", except that the forwarded destination is not another HTTP service but rather a gRPC service.

func DefaultHeaderMatcher

func DefaultHeaderMatcher(key string) (string, bool)

DefaultHeaderMatcher is used to pass http request headers to/from gRPC context. This adds permanent HTTP header keys (as specified by the IANA) to gRPC context with pbgo-grpc- prefix. HTTP headers that start with 'Grpc-Metadata-' are mapped to gRPC metadata after removing prefix 'Grpc-Metadata-'.

func NewServerMetadataContext

func NewServerMetadataContext(ctx context.Context, md ServerMetadata) context.Context

NewServerMetadataContext creates a new context with ServerMetadata

Types

type HeaderMatcherFunc

type HeaderMatcherFunc func(string) (string, bool)

HeaderMatcherFunc checks whether a header key should be forwarded to/from gRPC context.

type ServerMetadata

type ServerMetadata struct {
	HeaderMD  metadata.MD
	TrailerMD metadata.MD
}

ServerMetadata consists of metadata sent from gRPC server.

func ServerMetadataFromContext

func ServerMetadataFromContext(ctx context.Context) (md ServerMetadata, ok bool)

ServerMetadataFromContext returns the ServerMetadata in ctx

Jump to

Keyboard shortcuts

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