transport

package
v2.1.1-0...-182a82a Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: MIT Imports: 10 Imported by: 0

README

Transport

represents listener and caller implementations for various transports.

Documentation

Index

Constants

View Source
const (
	// StatusOK represents a 200 header status code
	StatusOK = 200
	// StatusInternalErr represents a 500 header status code
	StatusInternalErr = 500
)

Variables

This section is empty.

Functions

func StatusMessage

func StatusMessage(status int) string

StatusMessage attempts to lookup the message for the given status code. If no message has been found fot the given status code is a empty string returned.

Types

type Call

type Call interface {
	SendMsg(ctx context.Context, writer ResponseWriter, request *Request, refs references.Store) error
	GetMethods() []Method
	GetMethod(name string) Method
	Close() error
}

Call is a preconfigured interface for a single service

type Caller

type Caller interface {
	Name() string
	Dial(service *specs.Service, functions functions.Custom, options specs.Options, resolver discovery.Resolver) (Call, error)
}

Caller constructs new calls which could be used to call services

type Callers

type Callers []Caller

Callers represents a collection of callers

func (Callers) Get

func (collection Callers) Get(name string) Caller

Get attempts to return a caller with the given name

type Endpoint

type Endpoint struct {
	Listener string
	Flow     Flow
	Forward  *Forward
	Options  specs.Options
	Request  *Object
	Response *Object
	Errs     Errs
}

Endpoint represents a transport listener endpoint

func NewEndpoint

func NewEndpoint(listener string, flow Flow, forward *Forward, options specs.Options, request, response *specs.ParameterMap) *Endpoint

NewEndpoint constructs a new transport endpoint.

func (*Endpoint) NewCodec

func (endpoint *Endpoint) NewCodec(ctx *broker.Context, request codec.Constructor, response codec.Constructor) (err error)

NewCodec updates the endpoint request and response codecs and metadata managers. If a forwarding service is set is the request codec ignored.

type EndpointList

type EndpointList []*Endpoint

EndpointList represents a collection of transport endpoints

type ErrMalformedTemplate

type ErrMalformedTemplate struct {
	Template string
	Position int
	Cause    string
}

ErrMalformedTemplate is returned when unable to compile the URL template

func (ErrMalformedTemplate) Error

func (e ErrMalformedTemplate) Error() string

type Error

type Error interface {
	specs.ErrorHandle
	String() string
	Error() string
	Ptr() specs.ErrorHandle
}

Error represents a wrapped error and error specs

func Unwrap

func Unwrap(err error) Error

Unwrap returns the result of calling the Unwrap method on err, if err's type contains an transport Error returning error. Otherwise, Unwrap returns nil.

func WrapError

func WrapError(err error, handle specs.ErrorHandle) Error

WrapError returns an error with the error handle specs

type Errs

type Errs map[specs.ErrorHandle]*Object

Errs represents a err object collection

func (Errs) Get

func (collection Errs) Get(key Error) *Object

Get attempts to retrieve the requested object from the errs collection

func (Errs) Set

func (collection Errs) Set(err Error, object *Object)

Set appends the given object to the object collection

type Flow

type Flow interface {
	NewStore() references.Store
	GetName() string
	Errors() []Error
	Do(ctx context.Context, refs references.Store) error
	Wait()
}

Flow represents a flow which could be called by a transport

type Forward

type Forward struct {
	Schema  specs.Header
	Meta    *metadata.Manager
	Service *specs.Service
	Rewrite []Rewrite
}

Forward represents the forward specifications

func (*Forward) NewMeta

func (forward *Forward) NewMeta(ctx *broker.Context, resource string)

NewMeta updates the current object metadata manager

type Listener

type Listener interface {
	Name() string
	Serve() error
	Close() error
	Handle(*broker.Context, []*Endpoint, map[string]codec.Constructor) error
}

Listener specifies the listener implementation

type ListenerList

type ListenerList []Listener

ListenerList represents a collection of listeners

func (ListenerList) Get

func (collection ListenerList) Get(name string) Listener

Get attempts to return a listener with the given name

type Method

type Method interface {
	GetName() string
	References() []*specs.Property
}

Method represents a call method which could be called

type NewCaller

type NewCaller func(ctx *broker.Context) Caller

NewCaller constructs a new caller with the given context

type NewListener

type NewListener func(ctx *broker.Context) Listener

NewListener constructs a new listener with the given context

type Object

type Object struct {
	Definition *specs.ParameterMap
	StatusCode *specs.Property
	Message    *specs.Property
	Codec      codec.Manager
	Meta       *metadata.Manager
}

Object represents a data object.

func NewObject

func NewObject(schema *specs.ParameterMap, status *specs.Property, message *specs.Property) *Object

NewObject constructs a new data object

func (*Object) NewCodec

func (object *Object) NewCodec(ctx *broker.Context, resource string, codec codec.Constructor) error

NewCodec updates the given object to use the given codec. Errors returned while constructing a new codec manager are returned.

func (*Object) NewMeta

func (object *Object) NewMeta(ctx *broker.Context, resource string)

NewMeta updates the current object metadata manager

func (*Object) ResolveMessage

func (object *Object) ResolveMessage(store references.Store) string

ResolveMessage attempts to resolve the defined message. If no message property has been defined or the property is not a string. Is a internal server error message returned.

func (*Object) ResolveStatusCode

func (object *Object) ResolveStatusCode(store references.Store) int

ResolveStatusCode attempts to resolve the defined status code. If no status code property has been defined or the property is not a int64. Is a internal server error status returned.

type Request

type Request struct {
	RequestCodec  string
	ResponseCodec string
	Header        metadata.MD
	Method        Method
	Body          io.Reader
}

Request represents the request object given to a caller implementation used to make calls

type ResponseWriter

type ResponseWriter interface {
	io.WriteCloser
	Header() metadata.MD
	HeaderStatus(int)
	HeaderMessage(string)
}

ResponseWriter specifies the response writer implementation which could be used to both proxy forward a request or used to call a service

type Rewrite

type Rewrite func(string) (string, bool)

Rewrite describes a function which is applied to modify the request URL. Returns modified URL and true or source URL and false if does not match.

func NewRewrite

func NewRewrite(source, template string) (Rewrite, error)

NewRewrite prepares a rewrite function to be called by the handler before forwarding the request to the proxy.

type Writer

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

Writer represents a response writer

func NewResponseWriter

func NewResponseWriter(writer io.WriteCloser) *Writer

NewResponseWriter constructs a new response writer for the given io writer

func (*Writer) Close

func (rw *Writer) Close() error

Close closes the underlaying byte writer

func (*Writer) Header

func (rw *Writer) Header() metadata.MD

Header returns the response header

func (*Writer) HeaderMessage

func (rw *Writer) HeaderMessage(message string)

HeaderMessage sets the header message

func (*Writer) HeaderStatus

func (rw *Writer) HeaderStatus(status int)

HeaderStatus sets the header status

func (*Writer) Message

func (rw *Writer) Message() string

Message returns the header status message

func (*Writer) Status

func (rw *Writer) Status() int

Status returns the header status

func (*Writer) Write

func (rw *Writer) Write(bb []byte) (int, error)

Write writes the given byte buffer to the underlaying io Writer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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