Documentation ¶
Index ¶
- Constants
- Variables
- func AnnotateIncomingContext(ctx context.Context, req *http.Request, ...) (context.Context, error)
- func AnnotateOutgoingContext(ctx context.Context, req *http.Request, ...) (context.Context, error)
- func DefaultHeaderMatcher(key string) (string, bool)
- func NewServerMetadataContext(ctx context.Context, md ServerMetadata) context.Context
- type HeaderMatcherFunc
- type ServerMetadata
Constants ¶
const MetadataHeaderPrefix = "Grpc-Metadata-"
MetadataHeaderPrefix is the http prefix that represents custom metadata parameters to or from a gRPC call.
const MetadataPrefix = "pbgo-grpc-"
MetadataPrefix is prepended to permanent HTTP header keys (as specified by the IANA) when added to the gRPC context.
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 ¶
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 ¶
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 ¶
HeaderMatcherFunc checks whether a header key should be forwarded to/from gRPC context.
type ServerMetadata ¶
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