Documentation ¶
Index ¶
- Constants
- func RegisterSerializer(serializer Serializer)
- type CallTransporter
- type Client
- func (c *Client) Call(function string, requestData interface{}, responseData interface{}, ...) error
- func (c *Client) Request(function string) *RPC
- func (c *Client) WithMiddleware(middleware ...Middleware)
- func (c *Client) WithProtocolSerializer(serializer Serializer)
- func (c *Client) WithSerializer(serializer Serializer)
- type ListenTransporter
- type Middleware
- type Msg
- func (m *Msg) BindContent(content interface{}) (err error)
- func (m *Msg) ContentType() (contentType string, ok bool)
- func (m *Msg) Context() context.Context
- func (m *Msg) Function() (status string, ok bool)
- func (m *Msg) InternalError() *Msg
- func (m *Msg) Ok() *Msg
- func (m *Msg) Param(key string) *Param
- func (m *Msg) SetBinaryContent(content []byte) *Msg
- func (m *Msg) SetContent(content interface{}) *Msg
- func (m *Msg) SetContentType(contentType string) *Msg
- func (m *Msg) SetContentUsing(content interface{}, serializer Serializer) *Msg
- func (m *Msg) SetHeader(key string, value interface{}) *Msg
- func (m *Msg) SetParam(key string, value interface{}) *Msg
- func (m *Msg) SetParams(params ...Param) *Msg
- func (m *Msg) SetStatus(code int) *Msg
- func (m *Msg) Status() (status int, ok bool)
- func (m *Msg) UUID() (status string, ok bool)
- func (m *Msg) WithContext(ctx context.Context) *Msg
- type NextMiddleware
- type Param
- func (m *Param) Bool() (bool, bool)
- func (m *Param) BoolOr(def bool) bool
- func (m *Param) BoolSlice() ([]bool, bool)
- func (m *Param) BoolSliceOr(def []bool) []bool
- func (m *Param) Float() (float64, bool)
- func (m *Param) FloatOr(def float64) float64
- func (m *Param) FloatSlice() ([]float64, bool)
- func (m *Param) FloatSliceOr(def []float64) []float64
- func (m *Param) Int() (int64, bool)
- func (m *Param) IntOr(def int64) int64
- func (m *Param) IntSlice() ([]int64, bool)
- func (m *Param) IntSliceOr(def []int64) []int64
- func (m *Param) IsNil() bool
- func (m *Param) IsSlice() bool
- func (m *Param) Key() string
- func (m *Param) String() (string, bool)
- func (m *Param) StringOr(defaultTo string) string
- func (m *Param) StringSlice() ([]string, bool)
- func (m *Param) StringSliceOr(defaultTo []string) []string
- func (m *Param) Uint() (uint64, bool)
- func (m *Param) UintOr(def uint64) uint64
- func (m *Param) UintSlice() ([]uint64, bool)
- func (m *Param) UintSliceOr(def []uint64) []uint64
- func (m *Param) Value() interface{}
- type RPC
- func (r *RPC) Async() *RPCTransit
- func (r *RPC) BindResponseContent(content interface{}) *RPC
- func (r *RPC) Callbacks(msgCallback func(*Msg), errorCallback func(error)) *RPCTransit
- func (r *RPC) Channels() (<-chan *Msg, <-chan error)
- func (r *RPC) Done() error
- func (r *RPC) Error() error
- func (r *RPC) Get() (*Msg, error)
- func (r *RPC) WithBinaryContent(data []byte) *RPC
- func (r *RPC) WithContent(requestData interface{}) *RPC
- func (r *RPC) WithContentUsing(requestData interface{}, serializer Serializer) *RPC
- func (r *RPC) WithContext(ctx context.Context) *RPC
- func (r *RPC) WithMiddleware(middleware ...Middleware) *RPC
- func (r *RPC) WithParam(key string, value interface{}) *RPC
- func (r *RPC) WithParams(params ...Param) *RPC
- func (r *RPC) WithUUID(uuid string) *RPC
- type RPCError
- type RPCTransit
- type Serializer
- type Server
- func (s *Server) Handle(function string, handler func(request *Msg, response *Msg) error, ...)
- func (s *Server) HandleFunc(handler func(request *Msg, response *Msg) error, middleware ...Middleware)
- func (s *Server) WithMiddleware(middleware ...Middleware)
- func (s *Server) WithProtocolSerializer(serializer Serializer)
- func (s *Server) WithSerializer(serializer Serializer)
- type Transporter
Constants ¶
const HeaderContentType = "content-type"
HeaderContentType is the function name header param name
const HeaderFunction = "function"
HeaderFunction is the function name header param name
const HeaderStatus = "status"
HeaderStatus is the status header param name
const HeaderUUID = "status"
HeaderUUID is the uuid header param name
const StatusHandlerError = 510
StatusHandlerError the handler function of request failed
const StatusInternalError = 500
StatusInternalError rpc status internal server error
const StatusInternalPanic = 501
StatusInternalPanic rpc status internal server error when recovered from panic
const StatusMarshalError = 550
StatusMarshalError could not marshal data
const StatusOk = 200
StatusOk rpc status ok
const StatusUnmarshalError = 551
StatusUnmarshalError could not unmarshal data
Variables ¶
This section is empty.
Functions ¶
func RegisterSerializer ¶
func RegisterSerializer(serializer Serializer)
RegisterSerializer lets a user register a protocolSerializer for a specific content type this allow yarf to bind message content to that specific serial format. Yarf standard serializers can be registered by importing with side effect e.g. import _ "bitbucket.org/modfin/yarf/serializers"
Types ¶
type CallTransporter ¶
type CallTransporter interface {
Call(ctx context.Context, function string, requestData []byte) (response []byte, err error)
}
CallTransporter is the interface that must be fulfilled for a transporter to be used as a client.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a struct wrapping a transporting layer and methods for using yarf
func NewClient ¶
func NewClient(t CallTransporter) Client
NewClient create a new yarf client using a specific transporter
func (*Client) Call ¶
func (c *Client) Call(function string, requestData interface{}, responseData interface{}, requestParams ...Param) error
Call is a short hand performs a request from function name, and req param. The response is unmarshaled into resp
func (*Client) WithMiddleware ¶
func (c *Client) WithMiddleware(middleware ...Middleware)
WithMiddleware adds middleware to client request for pre and post processing
func (*Client) WithProtocolSerializer ¶
func (c *Client) WithProtocolSerializer(serializer Serializer)
WithProtocolSerializer sets the protocolSerializer used for transport.
func (*Client) WithSerializer ¶
func (c *Client) WithSerializer(serializer Serializer)
WithSerializer sets the contentSerializer used for content if not binary
type ListenTransporter ¶
type ListenTransporter interface { Listen(function string, toExec func(ctx context.Context, requestData []byte) (responseData []byte)) error Close() error }
ListenTransporter is the interface that must be fulfilled for a transporter to be used as a server
type Middleware ¶
type Middleware func(request *Msg, response *Msg, next NextMiddleware) error
Middleware the function that shall be implemented for a middleware
type Msg ¶
type Msg struct { Headers map[string]interface{} Content []byte // contains filtered or unexported fields }
Msg represents a message that is being passed between client and server
func (*Msg) BindContent ¶
BindContent is used to unmarshal/bind content data to input interface. It will look for a proper deserializer matching header content-type. Serializer can be registered by yarf.RegisterSerializer()
func (*Msg) ContentType ¶
ContentType returns the ContentType header of the request, if one exist
func (*Msg) Context ¶
Context returns the context of the message. This is primarily for use on the server side, in order to monitor Done from client side
func (*Msg) InternalError ¶
InternalError sets the status header to 500
func (*Msg) Param ¶
Param receives a param from the params header, it is wrapped in a param struct which implements helper methods in how to access params.
func (*Msg) SetBinaryContent ¶
SetBinaryContent sets the input data as content of the message
func (*Msg) SetContent ¶
SetContent sets the input interface as the content of the message
func (*Msg) SetContentType ¶
SetContentType sets the statues header of the message
func (*Msg) SetContentUsing ¶
func (m *Msg) SetContentUsing(content interface{}, serializer Serializer) *Msg
SetContentUsing serializes the content with a specific contentSerializer and sets it as a binary payload
func (*Msg) SetParam ¶
SetParam sets a param in the params header of the message. Which later provides helper methods of de/serializations and defaults.
func (*Msg) SetParams ¶
SetParams params in the params header of the message. Which later provides helper methods of de/serializations and defaults.
type Param ¶
type Param struct {
// contains filtered or unexported fields
}
Param is a key/value entry and a struct which implements helper methods to help with retrial of data types from value.
func (*Param) BoolSliceOr ¶
BoolSliceOr returns value as a []bool, otherwise the provided default
func (*Param) FloatSlice ¶
FloatSlice returns value as a []float64, if possible
func (*Param) FloatSliceOr ¶
FloatSliceOr returns value as a []float64, otherwise the provided default
func (*Param) IntSliceOr ¶
IntSliceOr returns value as a []int64, otherwise the provided default
func (*Param) StringSlice ¶
StringSlice returns value as a []string, if possible
func (*Param) StringSliceOr ¶
StringSliceOr returns value as a []string, otherwise the provided default
func (*Param) UintSliceOr ¶
UintSliceOr returns value as a []uint64, otherwise the provided default
type RPC ¶
type RPC struct {
// contains filtered or unexported fields
}
RPC represents a request to in yarf and is used to build a request using the builder pattern
func (*RPC) Async ¶
func (r *RPC) Async() *RPCTransit
Async returns a performs the request and return a transit object.
func (*RPC) BindResponseContent ¶
BindResponseContent will unmarshal response into interface passed into method
func (*RPC) Callbacks ¶
func (r *RPC) Callbacks(msgCallback func(*Msg), errorCallback func(error)) *RPCTransit
Callbacks sets a msgCallback function that will be called on success or failure, it does nothing if called after exec()
func (*RPC) Channels ¶
Channels returns msgChannel associated with the request Channels() will call UseChannel() and then exec() if exec() has not been called.
func (*RPC) Done ¶
Done waits until the rpc request is done and has returned a result. If the result is already resolved, the error will be returned directly
func (*RPC) Error ¶
Error return the error of the request, if any at the point of calling it. Meaning that it might return nil and later return a none nil value
func (*RPC) Get ¶
Get wait for request to be done before returning with the resulting message and error.
func (*RPC) WithBinaryContent ¶
WithBinaryContent sets requests content as a binary format and marshaling will not be preformed, it does nothing if called after exec()
func (*RPC) WithContent ¶
WithContent sets requests content, it does nothing if called after exec()
func (*RPC) WithContentUsing ¶
func (r *RPC) WithContentUsing(requestData interface{}, serializer Serializer) *RPC
WithContentUsing sets requests content with a specific protocolSerializer, it does nothing if called after exec()
func (*RPC) WithContext ¶
WithContext sets context of request for outside control, it does nothing if called after exec()
func (*RPC) WithMiddleware ¶
func (r *RPC) WithMiddleware(middleware ...Middleware) *RPC
WithMiddleware adds middleware to specific request.
func (*RPC) WithParam ¶
WithParam set a param that can be read by server side, like a query param in http requests, it does nothing if called after exec()
func (*RPC) WithParams ¶
WithParams set params provided that can be read by server side, like a query param in http requests, it does nothing if called after exec()
type RPCError ¶
RPCError struct for yarf rpc calls
func NewRPCError ¶
NewRPCError create a RPCError struct for yarf rpc calls
type RPCTransit ¶
type RPCTransit struct {
// contains filtered or unexported fields
}
RPCTransit represents a request to in yarf when in transit and the purpose of it is to restricts the function that are allowed to be called when the request in transit in order to expose internal state and what can be done.
func (*RPCTransit) Callbacks ¶
func (r *RPCTransit) Callbacks(callback func(*Msg), errorCallback func(error)) *RPCTransit
Callbacks sets a msgCallback function that will be called on success or failure, it does nothing if called after exec()
func (*RPCTransit) Channels ¶
func (r *RPCTransit) Channels() (<-chan *Msg, <-chan error)
Channels returns msgChannel associated with the request, these are created if UseChannels() is called before exec(). Channels() will call UseChannel() and then exec() if exec() has not been called.
func (*RPCTransit) Done ¶
func (r *RPCTransit) Done() error
Done waits until the rpc request is done and has returned a result. If the result is already resolved, the error will be returned directly
func (*RPCTransit) Error ¶
func (r *RPCTransit) Error() error
Error return the error of the request, if any at the point of calling it. Meaning that it might return nil and later return a none nil value.
func (*RPCTransit) Get ¶
func (r *RPCTransit) Get() (*Msg, error)
Get wait for request to be done before returning with the resulting message and error. It the response already is resolved it will return the resulting message or error without waiting for anything
type Serializer ¶
type Serializer struct { ContentType string Marshal func(v interface{}) ([]byte, error) Unmarshal func(data []byte, v interface{}) error }
Serializer is the interface that must be fulfilled for protocolSerializer of data before transport.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents a yarf server with a particular transporter
func NewServer ¶
func NewServer(t ListenTransporter, namespace ...string) Server
NewServer creates a new server with a particular server and name space of functions provided
func (*Server) Handle ¶
func (s *Server) Handle(function string, handler func(request *Msg, response *Msg) error, middleware ...Middleware)
Handle creates a server endpoint for yarf using the handler function, the name of function will be on the format "namespace.function" e.g. my-namespace.Add, if a string "Add" is passed into the function coupled with a handler function
func (*Server) HandleFunc ¶
func (s *Server) HandleFunc(handler func(request *Msg, response *Msg) error, middleware ...Middleware)
HandleFunc creates a server endpoint for yarf using the handler function, the name of function will be on the format "namespace.FunctionName" e.g. my-namespace.Add, if a function named Add is passed into the function
func (*Server) WithMiddleware ¶
func (s *Server) WithMiddleware(middleware ...Middleware)
WithMiddleware add middleware to all requests
func (*Server) WithProtocolSerializer ¶
func (s *Server) WithProtocolSerializer(serializer Serializer)
WithProtocolSerializer sets the protocolSerializer used for transport.
func (*Server) WithSerializer ¶
func (s *Server) WithSerializer(serializer Serializer)
WithSerializer sets the default protocolSerializer for content.
type Transporter ¶
type Transporter interface { CallTransporter ListenTransporter }
Transporter is the interface that must be fulfilled for a transporter.