http2

package module
v0.0.0-...-4c21634 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: Apache-2.0 Imports: 19 Imported by: 7

Documentation

Overview

Package codes defines the canonical error codes used by gRPC. It is consistent across various languages.

Package keepalive defines configurable parameters for point-to-point healthcheck.

Package metadata define the structure of the metadata supported by gRPC library. Please refer to https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md for more information about custom-metadata.

Package peer defines various peer information associated with RPCs and corresponding utils.

Package stats is for collecting and reporting various network and RPC stats. This package is for monitoring purpose only. All fields are read-only. All APIs are experimental.

Package status implements errors returned by gRPC. These errors are serialized and transmitted on the wire between server and client, and allow for additional data to be transmitted via the Details field in the status proto. gRPC service handlers should return an error created by this package, and gRPC clients should expect a corresponding error to be returned from the RPC call.

This package upholds the invariants that a non-nil error may not contain an OK code, and an OK code must result in a nil error.

package http2 defines and implements message oriented communication channel to complete various transactions (e.g., an RPC).

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConnClosing indicates that the transport is closing.
	ErrConnClosing = connectionErrorf(true, nil, "transport is closing")
	// ErrStreamDrain indicates that the stream is rejected by the server because
	// the server stops accepting new RPCs.
	ErrStreamDrain = streamErrorf(codesUnavailable, "the server stops accepting new RPCs")
)
View Source
var DefaultLogger = log.New(os.Stderr, "http2: ", log.Lshortfile)
View Source
var ErrIllegalHeaderWrite = errors.New("transport: the stream is done or WriteHeader was already called")

ErrIllegalHeaderWrite indicates that setting header is illegal because of the stream's state.

Functions

func AppendToOutgoingContext

func AppendToOutgoingContext(ctx context.Context, kv ...string) context.Context

AppendToOutgoingContext returns a new context with the provided kv merged with any existing metadata in the context. Please refer to the documentation of Pairs for a description of kv.

func NewIncomingContext

func NewIncomingContext(ctx context.Context, md Metadata) context.Context

NewIncomingContext creates a new context with incoming md attached.

func NewOutgoingContext

func NewOutgoingContext(ctx context.Context, md Metadata) context.Context

NewOutgoingContext creates a new context with outgoing md attached. If used in conjunction with AppendToOutgoingContext, NewOutgoingContext will overwrite any previously-appended metadata.

func OutgoingTags

func OutgoingTags(ctx context.Context) []byte

OutgoingTags returns the tags from the context for the outbound RPC.

This is intended for gRPC-internal use ONLY.

func OutgoingTrace

func OutgoingTrace(ctx context.Context) []byte

OutgoingTrace returns the trace from the context for the outbound RPC. It is intended for gRPC-internal use.

func SetIncomingTags

func SetIncomingTags(ctx context.Context, b []byte) context.Context

SetIncomingTags attaches stats tagging data to the context, to be read by the application (not sent in outgoing RPCs).

This is intended for gRPC-internal use ONLY.

func SetIncomingTrace

func SetIncomingTrace(ctx context.Context, b []byte) context.Context

SetIncomingTrace attaches stats tagging data to the context, to be read by the application (not sent in outgoing RPCs). It is intended for gRPC-internal use.

func SetTags

func SetTags(ctx context.Context, b []byte) context.Context

SetTags attaches stats tagging data to the context, which will be sent in the outgoing RPC with the header grpc-tags-bin. Subsequent calls to SetTags will overwrite the values from earlier calls.

NOTE: this is provided only for backward compatibility with existing clients and will likely be removed in an upcoming release. New uses should transmit this type of data using metadata with a different, non-reserved (i.e. does not begin with "grpc-") header name.

func SetTrace

func SetTrace(ctx context.Context, b []byte) context.Context

SetTrace attaches stats tagging data to the context, which will be sent in the outgoing RPC with the header grpc-trace-bin. Subsequent calls to SetTrace will overwrite the values from earlier calls.

NOTE: this is provided only for backward compatibility with existing clients and will likely be removed in an upcoming release. New uses should transmit this type of data using metadata with a different, non-reserved (i.e. does not begin with "grpc-") header name.

func Tags

func Tags(ctx context.Context) []byte

Tags returns the tags from the context for the inbound RPC.

NOTE: this is provided only for backward compatibility with existing clients and will likely be removed in an upcoming release. New uses should transmit this type of data using metadata with a different, non-reserved (i.e. does not begin with "grpc-") header name.

func Trace

func Trace(ctx context.Context) []byte

Trace returns the trace from the context for the inbound RPC.

NOTE: this is provided only for backward compatibility with existing clients and will likely be removed in an upcoming release. New uses should transmit this type of data using metadata with a different, non-reserved (i.e. does not begin with "grpc-") header name.

Types

type Begin

type Begin struct {
	// Client is true if this Begin is from client side.
	Client bool
	// BeginTime is the time when the RPC begins.
	BeginTime time.Time
	// FailFast indicates if this RPC is failfast.
	FailFast bool
}

Begin contains stats when an RPC begins. FailFast is only valid if this Begin is from client side.

func (*Begin) IsClient

func (s *Begin) IsClient() bool

IsClient indicates if the stats information is from client side.

type CallHdr

type CallHdr struct {
	// Host specifies the peer's host.
	Host string

	// Method specifies the operation to perform.
	Method string

	// RecvCompress specifies the compression algorithm applied on
	// inbound messages.
	RecvCompress string

	// SendCompress specifies the compression algorithm applied on
	// outbound message.
	SendCompress string

	// Flush indicates whether a new stream command should be sent
	// to the peer without waiting for the first data. This is
	// only a hint.
	// If it's true, the transport may modify the flush decision
	// for performance purposes.
	// If it's false, new stream will never be flushed.
	Flush bool
}

CallHdr carries the information of a particular RPC.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements the ClientTransport interface with HTTP2.

func NewClient

func NewClient(ctx context.Context, addr TargetInfo, opts ConnectOptions, timeout time.Duration) (_ *Client, err error)

NewClient constructs a connected Client to addr based on HTTP2 and starts to receive messages on it. Non-nil error returns if construction fails.

func (*Client) Close

func (t *Client) Close() (err error)

Close kicks off the shutdown process of the transport. This should be called only once on a transport. Once it is called, the transport should not be accessed any more.

func (*Client) CloseStream

func (t *Client) CloseStream(s *Stream, err error)

CloseStream clears the footprint of a stream when the stream is not needed any more. This must not be executed in reader's goroutine.

func (*Client) Error

func (t *Client) Error() <-chan struct{}

func (*Client) GetGoAwayReason

func (t *Client) GetGoAwayReason() GoAwayReason

func (*Client) GoAway

func (t *Client) GoAway() <-chan struct{}

func (*Client) GracefulClose

func (t *Client) GracefulClose() error

GracefulClose sets the state to draining, which prevents new streams from being created and causes the transport to be closed when the last active stream is closed. If there are no active streams, the transport is closed immediately. This does nothing if the transport is already draining or closing.

func (*Client) NewStream

func (t *Client) NewStream(ctx context.Context, callHdr *CallHdr) (_ *Stream, err error)

NewStream creates a stream and registers it into the transport as "active" streams.

func (*Client) Write

func (t *Client) Write(s *Stream, hdr []byte, data []byte, opts *Options) error

Write formats the data into HTTP2 data frame(s) and sends it out. The caller should proceed only if Write returns nil.

type ClientParameters

type ClientParameters struct {
	// After a duration of this time if the client doesn't see any activity it
	// pings the server to see if the transport is still alive.
	// If set below 10s, a minimum value of 10s will be used instead.
	Time time.Duration // The current default value is infinity.
	// After having pinged for keepalive check, the client waits for a duration
	// of Timeout and if no activity is seen even after that the connection is
	// closed.
	Timeout time.Duration // The current default value is 20 seconds.
	// If true, client sends keepalive pings even with no active RPCs. If false,
	// when there are no active RPCs, Time and Timeout will be ignored and no
	// keepalive pings will be sent.
	PermitWithoutStream bool // false by default.
}

ClientParameters is used to set keepalive parameters on the client-side. These configure how the client will actively probe to notice when a connection is broken and send pings so intermediaries will be aware of the liveness of the connection. Make sure these parameters are set in coordination with the keepalive policy on the server, as incompatible settings can result in closing of connection.

type Code

type Code uint32

A Code is an unsigned 32-bit error code as defined in the gRPC spec.

func WrapCode

func WrapCode(err error) Code

Code returns the Code of the error if it is a Status error, codesOK if err is nil, or codesUnknown otherwise.

func (Code) String

func (c Code) String() string

func (*Code) UnmarshalJSON

func (c *Code) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals b into the Code.

type ConnBegin

type ConnBegin struct {
	// Client is true if this ConnBegin is from client side.
	Client bool
}

ConnBegin contains the stats of a connection when it is established.

func (*ConnBegin) IsClient

func (s *ConnBegin) IsClient() bool

IsClient indicates if this is from client side.

type ConnEnd

type ConnEnd struct {
	// Client is true if this ConnEnd is from client side.
	Client bool
}

ConnEnd contains the stats of a connection when it ends.

func (*ConnEnd) IsClient

func (s *ConnEnd) IsClient() bool

IsClient indicates if this is from client side.

type ConnStats

type ConnStats interface {

	// IsClient returns true if this ConnStats is from client side.
	IsClient() bool
	// contains filtered or unexported methods
}

ConnStats contains stats information about connections.

type ConnTagInfo

type ConnTagInfo struct {
	// RemoteAddr is the remote address of the corresponding connection.
	RemoteAddr net.Addr
	// LocalAddr is the local address of the corresponding connection.
	LocalAddr net.Addr
}

ConnTagInfo defines the relevant information needed by connection context tagger.

type ConnectOptions

type ConnectOptions struct {
	// UserAgent is the application user agent.
	UserAgent string
	// Authority is the :authority pseudo-header to use. This field has no effect if
	// TransportCredentials is set.
	Authority string
	// Dialer specifies how to dial a network address.
	Dialer func(context.Context, string) (net.Conn, error)
	// FailOnNonTempDialError specifies if gRPC fails on non-temporary dial errors.
	FailOnNonTempDialError bool
	// KeepaliveParams stores the keepalive parameters.
	KeepaliveParams ClientParameters
	// StatsHandler stores the handler for stats.
	StatsHandler statsHandler
	// InitialWindowSize sets the initial window size for a stream.
	InitialWindowSize int32
	// InitialConnWindowSize sets the initial window size for a connection.
	InitialConnWindowSize int32
	// WriteBufferSize sets the size of write buffer which in turn determines how much data can be batched before it's written on the wire.
	WriteBufferSize int
	// ReadBufferSize sets the size of read buffer, which in turn determines how much data can be read at most for one read syscall.
	ReadBufferSize int
}

ConnectOptions covers all relevant options for communicating with the server.

type ConnectionError

type ConnectionError struct {
	Desc string
	// contains filtered or unexported fields
}

ConnectionError is an error that results in the termination of the entire connection and the retry of all the active streams.

func (ConnectionError) Error

func (e ConnectionError) Error() string

func (ConnectionError) Origin

func (e ConnectionError) Origin() error

Origin returns the original error of this connection error.

func (ConnectionError) Temporary

func (e ConnectionError) Temporary() bool

Temporary indicates if this connection error is temporary or fatal.

type End

type End struct {
	// Client is true if this End is from client side.
	Client bool
	// BeginTime is the time when the RPC began.
	BeginTime time.Time
	// EndTime is the time when the RPC ends.
	EndTime time.Time
	// Trailer contains the trailer metadata received from the server. This
	// field is only valid if this End is from the client side.
	// Deprecated: use Trailer in InTrailer instead.
	Trailer Metadata
	// Error is the error the RPC ended with. It is an error generated from
	// status.Status and can be converted back to status.Status using
	// status.FromError if non-nil.
	Error error
}

End contains stats when an RPC ends.

func (*End) IsClient

func (s *End) IsClient() bool

IsClient indicates if this is from client side.

type EnforcementPolicy

type EnforcementPolicy struct {
	// MinTime is the minimum amount of time a client should wait before sending
	// a keepalive ping.
	MinTime time.Duration // The current default value is 5 minutes.
	// If true, server allows keepalive pings even when there are no active
	// streams(RPCs). If false, and client sends ping when there are no active
	// streams, server will send GOAWAY and close the connection.
	PermitWithoutStream bool // false by default.
}

EnforcementPolicy is used to set keepalive enforcement policy on the server-side. Server will close connection with a client that violates this policy.

type GoAwayReason

type GoAwayReason uint8

GoAwayReason contains the reason for the GoAway frame received.

const (
	// Invalid indicates that no GoAway frame is received.
	Invalid GoAwayReason = 0
	// NoReason is the default value when GoAway frame is received.
	NoReason GoAwayReason = 1
	// TooManyPings indicates that a GoAway frame with ErrCodeEnhanceYourCalm
	// was received and that the debug data said "too_many_pings".
	TooManyPings GoAwayReason = 2
)

type InHeader

type InHeader struct {
	// Client is true if this InHeader is from client side.
	Client bool
	// WireLength is the wire length of header.
	WireLength int
	// Compression is the compression algorithm used for the RPC.
	Compression string
	// Header contains the header metadata received.
	Header Metadata

	// The following fields are valid only if Client is false.
	// FullMethod is the full RPC method string, i.e., /package.service/method.
	FullMethod string
	// RemoteAddr is the remote address of the corresponding connection.
	RemoteAddr net.Addr
	// LocalAddr is the local address of the corresponding connection.
	LocalAddr net.Addr
}

InHeader contains stats when a header is received.

func (*InHeader) IsClient

func (s *InHeader) IsClient() bool

IsClient indicates if the stats information is from client side.

type InPayload

type InPayload struct {
	// Client is true if this InPayload is from client side.
	Client bool
	// Payload is the payload with original type.
	Payload interface{}
	// Data is the serialized message payload.
	Data []byte
	// Length is the length of uncompressed data.
	Length int
	// WireLength is the length of data on wire (compressed, signed, encrypted).
	WireLength int
	// RecvTime is the time when the payload is received.
	RecvTime time.Time
}

InPayload contains the information for an incoming payload.

func (*InPayload) IsClient

func (s *InPayload) IsClient() bool

IsClient indicates if the stats information is from client side.

type InTrailer

type InTrailer struct {
	// Client is true if this InTrailer is from client side.
	Client bool
	// WireLength is the wire length of trailer.
	WireLength int
	// Trailer contains the trailer metadata received from the server. This
	// field is only valid if this InTrailer is from the client side.
	Trailer Metadata
}

InTrailer contains stats when a trailer is received.

func (*InTrailer) IsClient

func (s *InTrailer) IsClient() bool

IsClient indicates if the stats information is from client side.

type Metadata

type Metadata map[string][]string

Metadata is a mapping from metadata keys to values. Users should use the following two convenience functions New and Pairs to generate Metadata.

func FromIncomingContext

func FromIncomingContext(ctx context.Context) (md Metadata, ok bool)

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

func FromOutgoingContext

func FromOutgoingContext(ctx context.Context) (Metadata, bool)

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

func FromOutgoingContextRaw

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

FromOutgoingContextRaw returns the un-merged, intermediary contents of rawMetadata. Remember to perform strings.ToLower on the keys. The returned Metadata should not be modified. Writing to it may cause races. Modification should be made to copies of the returned Metadata.

This is intended for gRPC-internal use ONLY.

func Join

func Join(mds ...Metadata) Metadata

Join joins any number of mds into a single Metadata. The order of values for each key is determined by the order in which the mds containing those values are presented to Join.

func New

func New(m map[string]string) Metadata

New creates an MD from a given key-value map.

Only the following ASCII characters are allowed in keys:

  • digits: 0-9
  • uppercase letters: A-Z (normalized to lower)
  • lowercase letters: a-z
  • special characters: -_.

Uppercase letters are automatically converted to lowercase.

Keys beginning with "grpc-" are reserved for grpc-internal use only and may result in errors if set in metadata.

func Pairs

func Pairs(kv ...string) Metadata

Pairs returns an Metadata formed by the mapping of key, value ... Pairs panics if len(kv) is odd.

Only the following ASCII characters are allowed in keys:

  • digits: 0-9
  • uppercase letters: A-Z (normalized to lower)
  • lowercase letters: a-z
  • special characters: -_.

Uppercase letters are automatically converted to lowercase.

Keys beginning with "grpc-" are reserved for grpc-internal use only and may result in errors if set in metadata.

func (Metadata) Append

func (md Metadata) Append(k string, vals ...string)

Append adds the values to key k, not overwriting what was already stored at that key.

func (Metadata) Copy

func (md Metadata) Copy() Metadata

Copy returns a copy of md.

func (Metadata) Get

func (md Metadata) Get(k string) []string

Get obtains the values for a given key.

func (Metadata) Len

func (md Metadata) Len() int

Len returns the number of items in md.

func (Metadata) Set

func (md Metadata) Set(k string, vals ...string)

Set sets the value of a given key with a slice of values.

type Options

type Options struct {
	// Last indicates whether this write is the last piece for
	// this stream.
	Last bool

	// Delay is a hint to the transport implementation for whether
	// the data could be buffered for a batching write. The
	// transport implementation may ignore the hint.
	Delay bool
}

Options provides additional hints and information for message transmission.

type OutHeader

type OutHeader struct {
	// Client is true if this OutHeader is from client side.
	Client bool
	// Compression is the compression algorithm used for the RPC.
	Compression string
	// Header contains the header metadata sent.
	Header Metadata

	// The following fields are valid only if Client is true.
	// FullMethod is the full RPC method string, i.e., /package.service/method.
	FullMethod string
	// RemoteAddr is the remote address of the corresponding connection.
	RemoteAddr net.Addr
	// LocalAddr is the local address of the corresponding connection.
	LocalAddr net.Addr
}

OutHeader contains stats when a header is sent.

func (*OutHeader) IsClient

func (s *OutHeader) IsClient() bool

IsClient indicates if this stats information is from client side.

type OutPayload

type OutPayload struct {
	// Client is true if this OutPayload is from client side.
	Client bool
	// Payload is the payload with original type.
	Payload interface{}
	// Data is the serialized message payload.
	Data []byte
	// Length is the length of uncompressed data.
	Length int
	// WireLength is the length of data on wire (compressed, signed, encrypted).
	WireLength int
	// SentTime is the time when the payload is sent.
	SentTime time.Time
}

OutPayload contains the information for an outgoing payload.

func (*OutPayload) IsClient

func (s *OutPayload) IsClient() bool

IsClient indicates if this stats information is from client side.

type OutTrailer

type OutTrailer struct {
	// Client is true if this OutTrailer is from client side.
	Client bool
	// WireLength is the wire length of trailer.
	//
	// Deprecated: This field is never set. The length is not known when this message is
	// emitted because the trailer fields are compressed with hpack after that.
	WireLength int
	// Trailer contains the trailer metadata sent to the client. This
	// field is only valid if this OutTrailer is from the server side.
	Trailer Metadata
}

OutTrailer contains stats when a trailer is sent.

func (*OutTrailer) IsClient

func (s *OutTrailer) IsClient() bool

IsClient indicates if this stats information is from client side.

type Peer

type Peer struct {
	// Addr is the peer address.
	Addr net.Addr
}

Peer contains the information of the peer for an RPC, such as the address and authentication information.

func PeerFromContext

func PeerFromContext(ctx context.Context) (p *Peer, ok bool)

PeerFromContext returns the peer saved in ctx.

type RPCStats

type RPCStats interface {

	// IsClient returns true if this RPCStats is from client side.
	IsClient() bool
	// contains filtered or unexported methods
}

RPCStats contains stats information about RPCs.

type RPCTagInfo

type RPCTagInfo struct {
	// FullMethodName is the RPC method in the format of /package.service/method.
	FullMethodName string
	// FailFast indicates if this RPC is failfast.
	// This field is only valid on client side, it's always false on server side.
	FailFast bool
}

RPCTagInfo defines the relevant information needed by RPC context tagger.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server implements the ServerTransport interface with HTTP2.

func NewServer

func NewServer(conn net.Conn, config *ServerConfig) (_ *Server, err error)

NewServer constructs a ServerTransport based on HTTP2. ConnectionError is returned if something goes wrong.

func (*Server) Close

func (t *Server) Close() error

Close starts shutting down the Server transport. TODO(zhaoq): Now the destruction is not blocked on any pending streams. This could cause some resource issue. Revisit this later.

func (*Server) Drain

func (t *Server) Drain()

func (*Server) HandleStreams

func (t *Server) HandleStreams(handle func(*Stream), traceCtx func(context.Context, string) context.Context)

HandleStreams receives incoming streams using the given handler. This is typically run in a separate goroutine. traceCtx attaches trace to ctx and returns the new context.

func (*Server) RemoteAddr

func (t *Server) RemoteAddr() net.Addr

func (*Server) Write

func (t *Server) Write(s *Stream, hdr []byte, data []byte, opts *Options) (err error)

Write converts the data into HTTP2 data frame and sends it out. Non-nil error is returns if it fails (e.g., framing error, transport error).

func (*Server) WriteHeader

func (t *Server) WriteHeader(s *Stream, md Metadata) error

WriteHeader sends the header metedata md back to the client.

func (*Server) WriteStatus

func (t *Server) WriteStatus(s *Stream, st *Status) error

WriteStatus sends stream status to the client and terminates the stream. There is no further I/O operations being able to perform on this stream. TODO(zhaoq): Now it indicates the end of entire stream. Revisit if early OK is adopted.

type ServerConfig

type ServerConfig struct {
	MaxStreams            uint32
	StatsHandler          statsHandler
	KeepaliveParams       ServerParameters
	KeepalivePolicy       EnforcementPolicy
	InitialWindowSize     int32
	InitialConnWindowSize int32
	WriteBufferSize       int
	ReadBufferSize        int
}

ServerConfig consists of all the configurations to establish a server transport.

type ServerParameters

type ServerParameters struct {
	// MaxConnectionIdle is a duration for the amount of time after which an
	// idle connection would be closed by sending a GoAway. Idleness duration is
	// defined since the most recent time the number of outstanding RPCs became
	// zero or the connection establishment.
	MaxConnectionIdle time.Duration // The current default value is infinity.
	// MaxConnectionAge is a duration for the maximum amount of time a
	// connection may exist before it will be closed by sending a GoAway. A
	// random jitter of +/-10% will be added to MaxConnectionAge to spread out
	// connection storms.
	MaxConnectionAge time.Duration // The current default value is infinity.
	// MaxConnectionAgeGrace is an additive period after MaxConnectionAge after
	// which the connection will be forcibly closed.
	MaxConnectionAgeGrace time.Duration // The current default value is infinity.
	// After a duration of this time if the server doesn't see any activity it
	// pings the client to see if the transport is still alive.
	// If set below 1s, a minimum value of 1s will be used instead.
	Time time.Duration // The current default value is 2 hours.
	// After having pinged for keepalive check, the server waits for a duration
	// of Timeout and if no activity is seen even after that the connection is
	// closed.
	Timeout time.Duration // The current default value is 20 seconds.
}

ServerParameters is used to set keepalive and max-age parameters on the server-side.

type Status

type Status struct {
	// contains filtered or unexported fields
}

Status represents an RPC status code, message, and details. It is immutable and should be created with New, Newf, or FromProto.

func Convert

func Convert(err error) *Status

Convert is a convenience function which removes the need to handle the boolean return value from FromError.

func FromContextError

func FromContextError(err error) *Status

FromContextError converts a context error into a Status. It returns a Status with codesOK if err is nil, or a Status with codesUnknown if err is non-nil and not a context error.

func FromError

func FromError(err error) (s *Status, ok bool)

FromError returns a Status representing err if it was produced from this package or has a method `GRPCStatus() *Status`. Otherwise, ok is false and a Status is returned with codesUnknown and the original error message.

func (*Status) Code

func (s *Status) Code() Code

Code returns the status code contained in s.

func (*Status) Err

func (s *Status) Err() error

Err returns an immutable error representing s; returns nil if s.Code() is OK.

func (*Status) Message

func (s *Status) Message() string

Message returns the message contained in s.

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream represents an RPC in the transport layer.

func StreamFromContext

func StreamFromContext(ctx context.Context) (s *Stream, ok bool)

StreamFromContext returns the stream saved in ctx.

func (*Stream) BytesReceived

func (s *Stream) BytesReceived() bool

BytesReceived indicates whether any bytes have been received on this stream.

func (*Stream) BytesSent

func (s *Stream) BytesSent() bool

BytesSent indicates whether any bytes have been sent on this stream.

func (*Stream) Context

func (s *Stream) Context() context.Context

Context returns the context of the stream.

func (*Stream) Done

func (s *Stream) Done() <-chan struct{}

Done returns a chanel which is closed when it receives the final status from the server.

func (*Stream) GoAway

func (s *Stream) GoAway() <-chan struct{}

GoAway returns a channel which is closed when the server sent GoAways signal before this stream was initiated.

func (*Stream) GoString

func (s *Stream) GoString() string

GoString is implemented by Stream so context.String() won't race when printing %#v.

func (*Stream) Header

func (s *Stream) Header() (Metadata, error)

Header acquires the key-value pairs of header metadata once it is available. It blocks until i) the metadata is ready or ii) there is no header metadata or iii) the stream is canceled/expired.

func (*Stream) Method

func (s *Stream) Method() string

Method returns the method for the stream.

func (*Stream) Read

func (s *Stream) Read(p []byte) (n int, err error)

Read reads all p bytes from the wire for this stream.

func (*Stream) RecvCompress

func (s *Stream) RecvCompress() string

RecvCompress returns the compression algorithm applied to the inbound message. It is empty string if there is no compression applied.

func (*Stream) Server

func (s *Stream) Server() *Server

Server returns the underlying Server for the stream. The client side stream always returns nil.

func (*Stream) SetHeader

func (s *Stream) SetHeader(md Metadata) error

SetHeader sets the header metadata. This can be called multiple times. Server side only.

func (*Stream) SetSendCompress

func (s *Stream) SetSendCompress(str string)

SetSendCompress sets the compression algorithm to the stream.

func (*Stream) SetTrailer

func (s *Stream) SetTrailer(md Metadata) error

SetTrailer sets the trailer metadata which will be sent with the RPC status by the server. This can be called multiple times. Server side only.

func (*Stream) Status

func (s *Stream) Status() *Status

Status returns the status received from the server.

func (*Stream) Trailer

func (s *Stream) Trailer() Metadata

Trailer returns the cached trailer metedata. Note that if it is not called after the entire stream is done, it could return an empty Metadata. Client side only.

type StreamError

type StreamError struct {
	Code Code
	Desc string
}

StreamError is an error that only affects one stream within a connection.

func ContextErr

func ContextErr(err error) StreamError

ContextErr converts the error from context package into a StreamError.

func (StreamError) Error

func (e StreamError) Error() string

type TargetInfo

type TargetInfo struct {
	Addr     string
	Metadata interface{}
}

TargetInfo contains the information of the target such as network address and metadata.

Jump to

Keyboard shortcuts

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