Documentation ¶
Index ¶
- func IsTimeout(err error) bool
- type Worker
- func (w *Worker) ConnectedAddress() net.Addr
- func (w *Worker) ConvertValue(inputType reflect.Type, input interface{}) (output interface{}, err error)
- func (w *Worker) MakeWorkerFunction(workerFunction interface{}) gototo.WorkerFunction
- func (w *Worker) Quit()
- func (w *Worker) RegisterWorkerFunction(name string, workerFunction gototo.WorkerFunction)
- func (w *Worker) Run() (err error)
- func (w *Worker) SetAddress(net, laddr string)
- func (w *Worker) SetConvertTypeDecoderConfig(config *gototo.DecoderConfig)
- func (w *Worker) SetConvertTypeTagName(tagName string)
- func (w *Worker) SetDefaultContentType(contentType string)
- func (w *Worker) SetLogMetrics(logMetrics bool)
- func (w *Worker) SetMarshalFunction(marshal gototo.MarshalFunction)
- func (w *Worker) SetUnmarshalFunction(unmarshal gototo.UnmarshalFunction)
- func (w *Worker) Start() (err error)
- func (w *Worker) Stop()
- func (w *Worker) Wait()
- type WorkerConnection
- func (c *WorkerConnection) Call(method string, parameters interface{}) (response interface{}, err error)
- func (c *WorkerConnection) CallWithOptions(method string, parameters interface{}, options *gototo.RequestOptions) (response interface{}, err error)
- func (c *WorkerConnection) Connect(endpoint string) error
- func (c *WorkerConnection) ConvertValue(inputType reflect.Type, input interface{}) (output interface{}, err error)
- func (c *WorkerConnection) Disconnect(endpoint string) error
- func (c *WorkerConnection) GetEndpoints() (endpoints []string)
- func (c *WorkerConnection) PendingRequestCount() int
- func (c *WorkerConnection) RegisterDefaultOptions(method string, options *gototo.RequestOptions)
- func (c *WorkerConnection) RegisterResponseType(method string, i interface{}, wrappedInResponse bool)
- func (c *WorkerConnection) SetConvertTypeDecoderConfig(config *gototo.DecoderConfig)
- func (c *WorkerConnection) SetConvertTypeTagName(tagName string)
- func (c *WorkerConnection) SetEndpoints(endpoint ...string) error
- func (c *WorkerConnection) SetMarshalFunction(marshal gototo.ClientMarshalFunction)
- func (c *WorkerConnection) SetUnmarshalFunction(unmarshal gototo.ClientUnmarshalFunction)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker listens for requests and invokes registered goroutines when called.
func New ¶
Create a new worker bound to laddr that will run at most count functions at a time. If count == 0, it will default to runtime.NumCPU().
func (*Worker) ConnectedAddress ¶
func (*Worker) ConvertValue ¶
func (w *Worker) ConvertValue(inputType reflect.Type, input interface{}) (output interface{}, err error)
ConvertValue is a convenience method for converting a received interface{} to a specified type. It may be used e.g. when a JSON request is parsed to a map[string]interface{} and you want to turn it into a struct.
func (*Worker) MakeWorkerFunction ¶
func (w *Worker) MakeWorkerFunction(workerFunction interface{}) gototo.WorkerFunction
func (*Worker) RegisterWorkerFunction ¶
func (w *Worker) RegisterWorkerFunction(name string, workerFunction gototo.WorkerFunction)
RegisterWorkerFunction adds a new worker function that will be invoked when requests are received with the named method.
func (*Worker) SetAddress ¶
func (*Worker) SetConvertTypeDecoderConfig ¶
func (w *Worker) SetConvertTypeDecoderConfig(config *gototo.DecoderConfig)
SetConvertTypeDecoderConfig sets the mapstructure config to use when decoding. if set, it takes precidence over SetConvertTypeTagName
func (*Worker) SetConvertTypeTagName ¶
SetConvertTypeTagName sets the tag name to use to find field information when converting request parameters to custom types. By default this is "json"
func (*Worker) SetDefaultContentType ¶
func (*Worker) SetLogMetrics ¶
SetLogMetrics enables or disables metric logging
func (*Worker) SetMarshalFunction ¶
func (w *Worker) SetMarshalFunction(marshal gototo.MarshalFunction)
func (*Worker) SetUnmarshalFunction ¶
func (w *Worker) SetUnmarshalFunction(unmarshal gototo.UnmarshalFunction)
type WorkerConnection ¶
type WorkerConnection struct {
// contains filtered or unexported fields
}
WorkerConnection is used to make RPCs to remote workers. If multiple workers are connected, requests will be round-robin load balanced between them.
func NewConnection ¶
func NewConnection(endpoints ...string) *WorkerConnection
NewConnection creates a new WorkerConnection and optionally prepares it to connect to one or more endpoints.
func (*WorkerConnection) Call ¶
func (c *WorkerConnection) Call(method string, parameters interface{}) (response interface{}, err error)
Call calls a method on a worker and blocks until it receives a response. Use RegisterResponseType to automatically convert responses into the correct type. Use RegisterDefaultOptions to set a RequestOptions to use with a given method.
func (*WorkerConnection) CallWithOptions ¶
func (c *WorkerConnection) CallWithOptions(method string, parameters interface{}, options *gototo.RequestOptions) (response interface{}, err error)
CallWithOptions calls a method on a worker and blocks until it receives a response. Use RegisterResponseType to automatically convert responses into the correct type. This method is like Call but allows the caller to specify RequestOptions.
func (*WorkerConnection) Connect ¶
func (c *WorkerConnection) Connect(endpoint string) error
Connect connects to a new endpoint
func (*WorkerConnection) ConvertValue ¶
func (c *WorkerConnection) ConvertValue(inputType reflect.Type, input interface{}) (output interface{}, err error)
ConvertValue is a convenience method for converting a received interface{} to a specified type. It may be used e.g. when a JSON response is parsed to a map[string]interface{} and you want to turn it into a struct.
func (*WorkerConnection) Disconnect ¶
func (c *WorkerConnection) Disconnect(endpoint string) error
Disconnect disconnects from an existing endpoint
func (*WorkerConnection) GetEndpoints ¶
func (c *WorkerConnection) GetEndpoints() (endpoints []string)
GetEndpoints returns all endpoints that the WorkerConnection is connected to.
func (*WorkerConnection) PendingRequestCount ¶
func (c *WorkerConnection) PendingRequestCount() int
PendingRequestCount returns the number of requests currently awaiting responses
func (*WorkerConnection) RegisterDefaultOptions ¶
func (c *WorkerConnection) RegisterDefaultOptions(method string, options *gototo.RequestOptions)
RegisterDefaultOptions sets the options that will be used whenever Call is used for a given method. This does not affect CallWithOptions.
func (*WorkerConnection) RegisterResponseType ¶
func (c *WorkerConnection) RegisterResponseType(method string, i interface{}, wrappedInResponse bool)
RegisterResponseType ensures that responses from calls to the named method are converted to the proper type before being returned to the caller. If wrappedInResponse is true then the response will be parsed into a Response struct before reading the result from Response.Result and any error from the Response will be returned as an *ResponseError from the ConverterFunction.
func (*WorkerConnection) SetConvertTypeDecoderConfig ¶
func (c *WorkerConnection) SetConvertTypeDecoderConfig(config *gototo.DecoderConfig)
SetConvertTypeDecoderConfig sets the mapstructure config to use when decoding. if set, it takes precidence over SetConvertTypeTagName
func (*WorkerConnection) SetConvertTypeTagName ¶
func (c *WorkerConnection) SetConvertTypeTagName(tagName string)
SetConvertTypeTagName sets the tag name to use to find field information when converting request parameters to custom types. By default this is "json"
func (*WorkerConnection) SetEndpoints ¶
func (c *WorkerConnection) SetEndpoints(endpoint ...string) error
SetEndpoints connects to any new endpoints contained in the supplied list and disconnects from any current endpoints not in the list.
func (*WorkerConnection) SetMarshalFunction ¶
func (c *WorkerConnection) SetMarshalFunction(marshal gototo.ClientMarshalFunction)
SetMarshalFunction sets the function used to marshal requests for transmission.
func (*WorkerConnection) SetUnmarshalFunction ¶
func (c *WorkerConnection) SetUnmarshalFunction(unmarshal gototo.ClientUnmarshalFunction)
SetUnmarshalFunction sets the function used to unmarshal responses.