encoding

package
v1.25.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2017 License: MIT Imports: 4 Imported by: 18

Documentation

Overview

Package encoding provides APIs for encoding authors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

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

Call provides information about the current request inside handlers.

func CallFromContext

func CallFromContext(ctx context.Context) *Call

CallFromContext retrieves information about the current incoming request from the given context. Returns nil if the context is not a valid request context.

The object is valid only as long as the request is ongoing.

func (*Call) Caller

func (c *Call) Caller() string

Caller returns the name of the service making this request.

func (*Call) Encoding

func (c *Call) Encoding() transport.Encoding

Encoding returns the encoding for this request.

func (*Call) Header

func (c *Call) Header(k string) string

Header returns the value of the given request header provided with the request.

func (*Call) HeaderNames

func (c *Call) HeaderNames() []string

HeaderNames returns a sorted list of the names of user defined headers provided with this request.

func (*Call) Procedure

func (c *Call) Procedure() string

Procedure returns the name of the procedure being called.

func (*Call) RoutingDelegate

func (c *Call) RoutingDelegate() string

RoutingDelegate returns the routing delegate for this request.

func (*Call) RoutingKey

func (c *Call) RoutingKey() string

RoutingKey returns the routing key for this request.

func (*Call) Service

func (c *Call) Service() string

Service returns the name of the service being called.

func (*Call) ShardKey

func (c *Call) ShardKey() string

ShardKey returns the shard key for this request.

func (*Call) WriteResponseHeader

func (c *Call) WriteResponseHeader(k, v string) error

WriteResponseHeader writes headers to the response of this call.

type CallOption

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

CallOption defines options that may be passed in at call sites to other services.

Encoding authors should accept yarpc.CallOptions and convert them to encoding.CallOptions to use with NewOutboundCall. This will keep the API for service authors simple.

func ResponseHeaders

func ResponseHeaders(h *map[string]string) CallOption

ResponseHeaders specifies that headers received in response to this request should replace the given map.

func WithHeader

func WithHeader(k, v string) CallOption

WithHeader adds a new header to the request.

func WithRoutingDelegate

func WithRoutingDelegate(rd string) CallOption

WithRoutingDelegate sets the routing delegate for the request.

func WithRoutingKey

func WithRoutingKey(rk string) CallOption

WithRoutingKey sets the routing key for the request.

func WithShardKey

func WithShardKey(sk string) CallOption

WithShardKey sets the shard key for the request.

type InboundCall

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

InboundCall holds information about the inbound call and its response.

Encoding authors may use InboundCall to provide information about the incoming request on the Context and send response headers through WriteResponseHeader.

func NewInboundCall

func NewInboundCall(ctx context.Context) (context.Context, *InboundCall)

NewInboundCall builds a new InboundCall with the given context.

A request context is returned and must be used in place of the original.

func (*InboundCall) ReadFromRequest

func (ic *InboundCall) ReadFromRequest(req *transport.Request) error

ReadFromRequest reads information from the given request.

This information may be queried on the context using functions like Caller, Service, Procedure, etc.

func (*InboundCall) WriteToResponse

func (ic *InboundCall) WriteToResponse(resw transport.ResponseWriter) error

WriteToResponse writes response information from the InboundCall onto the given ResponseWriter.

If used, this must be called before writing the response body to the ResponseWriter.

type OutboundCall

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

OutboundCall is an outgoing call. It holds per-call options for a request.

Encoding authors may use OutboundCall to provide a CallOption-based request customization mechanism, including returning response headers through ResponseHeaders.

func NewOutboundCall

func NewOutboundCall(options ...CallOption) *OutboundCall

NewOutboundCall constructs a new OutboundCall with the given options.

func (*OutboundCall) ReadFromResponse

func (c *OutboundCall) ReadFromResponse(ctx context.Context, res *transport.Response) (context.Context, error)

ReadFromResponse reads information from the response for this call.

This should be called only if the request is unary.

func (*OutboundCall) WriteToRequest

func (c *OutboundCall) WriteToRequest(ctx context.Context, req *transport.Request) (context.Context, error)

WriteToRequest fills the given request with request-specific options from the call.

The context MAY be replaced by the OutboundCall.

Jump to

Keyboard shortcuts

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