wrpendpoint

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package wrpendpoint integrates go-kit endpoints with the notion of services that consume and emit WRP. Code in this package is transport-neutral. See the wrp/wrphttp package for HTTP-specific integrations with go-kit's transport/http package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(s Service) endpoint.Endpoint

New constructs a go-kit endpoint for the given WRP service. This endpoint enforces the constraint that ctx must be the context associated with the Request.

Types

type Note

type Note interface {
	// Destination returns the WRP destination string from the decoded message
	Destination() string

	// TransactionID returns the transaction identifier, if any
	TransactionID() string

	// Message returns the underlying decoded WRP message.  This can be nil in the case of
	// raw messages.  Callers should never modify the returned Message instance.
	Message() *wrp.Message

	// Encode writes out the WRP message fronted by this Note in the format supported by the pool.
	Encode(output io.Writer, format wrp.Format) error

	// EncodeBytes works like Encode, except that it returns a []byte.
	EncodeBytes(format wrp.Format) ([]byte, error)
}

Note is the core type implemented by any entity which carries a WRP message.

type Request

type Request interface {
	Note

	// Logger returns the enriched logger associated with this Request.  Client code should take care
	// to preserve this logger when changing loggers via WithLogger.
	//
	// If the logger associated with this Request is nil, for example via WithLogger(nil), this method
	// returns logging.DefaultLogger().
	Logger() log.Logger

	// WithLogger produces a shallow copy of this Request with a new Logger.  Generally, when creating a new
	// request logger, start with Logger():
	//
	//    var request Request = ...
	//    request = request.WithLogger(log.With(request.Logger(), "more", "stuff"))
	WithLogger(log.Logger) Request
}

Request is a WRP request. In addition to implementing Note, this type also provides contextual logging. A Request is considered immutable once instantiated. Methods that update a Request return a shallow copy with the modification.

func DecodeRequest

func DecodeRequest(logger log.Logger, source io.Reader, format wrp.Format) (Request, error)

DecodeRequest extracts a WRP request from the given source.

func DecodeRequestBytes

func DecodeRequestBytes(logger log.Logger, contents []byte, format wrp.Format) (Request, error)

DecodeRequestBytes returns a Request taken from the contents. The given pool is used to decode the WRP message.

This function also enhances the given logger with contextual information about the returned WRP request. The logger that is passed to this function should never be nil and should never have a Caller or DefaultCaller set.

func WrapAsRequest

func WrapAsRequest(logger log.Logger, m *wrp.Message) Request

WrapAsRequest takes an existing WRP message and produces a Request for that message.

type Response

type Response interface {
	Note
	tracing.Mergeable
}

Response represents a WRP response to a Request. Note that not all WRP requests will have responses, e.g. SimpleEvents. A Response instance is considered immutable once created. Methods that modify a response will return a shallow copy with the modification.

func DecodeResponse

func DecodeResponse(source io.Reader, format wrp.Format) (Response, error)

DecodeResponse extracts a WRP response from the given source.

func DecodeResponseBytes

func DecodeResponseBytes(contents []byte, format wrp.Format) (Response, error)

DecodeResponseBytes returns a Response taken from the contents. The given pool is used to decode the WRP message.

func WrapAsResponse

func WrapAsResponse(m *wrp.Message) Response

WrapAsResponse takes an existing WRP message and produces a Response for that message.

type Service

type Service interface {
	// ServeWRP processes a WRP request.  Either the Response or the error
	// returned from this method will be nil, but not both.
	ServeWRP(context.Context, Request) (Response, error)
}

Service represents a component which processes WRP transactions.

func Wrap

func Wrap(e endpoint.Endpoint) Service

Wrap does the opposite of New: it takes a go-kit endpoint and returns a Service that invokes it.

type ServiceFunc

type ServiceFunc func(context.Context, Request) (Response, error)

ServiceFunc is a function type that implements Service

func (ServiceFunc) ServeWRP

func (sf ServiceFunc) ServeWRP(ctx context.Context, r Request) (Response, error)

Jump to

Keyboard shortcuts

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