grpc: Index | Files

package grpcutil

import ""

Package grpcutil provides a bunch of utility functions to be used across the gRPC codebase.


Package Files

encode_duration.go metadata.go method.go target.go

func ContentSubtype Uses

func ContentSubtype(contentType string) (string, bool)

ContentSubtype returns the content-subtype for the given content-type. The given content-type must be a valid content-type that starts with "application/grpc". A content-subtype will follow "application/grpc" after a "+" or ";". See for more details.

If contentType is not a valid content-type for gRPC, the boolean will be false, otherwise true. If content-type == "application/grpc", "application/grpc+", or "application/grpc;", the boolean will be true, but no content-subtype will be returned.

contentType is assumed to be lowercase already.

func ContentType Uses

func ContentType(contentSubtype string) string

ContentType builds full content type with the given sub-type.

contentSubtype is assumed to be lowercase

func EncodeDuration Uses

func EncodeDuration(t time.Duration) string

EncodeDuration encodes the duration to the format grpc-timeout header accepts.

func ExtraMetadata Uses

func ExtraMetadata(ctx context.Context) (md metadata.MD, ok bool)

ExtraMetadata returns the incoming metadata in ctx if it exists. The returned MD should not be modified. Writing to it may cause races. Modification should be made to copies of the returned MD.

func ParseMethod Uses

func ParseMethod(methodName string) (service, method string, _ error)

ParseMethod splits service and method from the input. It expects format "/service/method".

func ParseTarget Uses

func ParseTarget(target string, skipUnixColonParsing bool) (ret resolver.Target)

ParseTarget splits target into a resolver.Target struct containing scheme, authority and endpoint. skipUnixColonParsing indicates that the parse should not parse "unix:[path]" cases. This should be true in cases where a custom dialer is present, to prevent a behavior change.

If target is not a valid scheme://authority/endpoint, it returns {Endpoint: target}.

func WithExtraMetadata Uses

func WithExtraMetadata(ctx context.Context, md metadata.MD) context.Context

WithExtraMetadata creates a new context with incoming md attached.

Package grpcutil imports 7 packages (graph) and is imported by 8 packages. Updated 2020-10-17. Refresh now. Tools for package owners.