Documentation ¶
Index ¶
Constants ¶
const ( StatusSuccess = "success" StatusOK = "ok" StatusError = "error" )
Variables ¶
var ErrAlreadySubscribed = errors.New("subscription already exists for ID")
ErrAlreadySubscribed is returned by ResponseHandler when there is already a subscription to an ID.
var ErrNotSubscribed = errors.New("no subscription for ID")
ErrNotSubscribed is returned by ResponseHandler when there is no subscription to an ID.
var ErrUnknownType = errors.New("unrecognized type")
ErrUnknownType is returned when the system encounters an unregistered type.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { // Call executes a task on a remote server. // An implementation of Execer interface over there will execute the task. Call(ctx context.Context, request TaskRequest) (err error) // CallWithResponse executes a task on a remote server. // An implementation of ExecerWithResponder can send responses back to the caller. CallWithResponse(ctx context.Context, request TaskRequest) (response <-chan TaskResponse, stop chan<- struct{}, err error) // CallWithDeadline executes a task on a remote server. // An implementation of ExecerWithResponder can will receive a Context with the deadline specified as a parameter. // The deadline refers to the deadline until the caller accepts responses. CallWithDeadline(ctx context.Context, request TaskRequest, deadline time.Time) (response <-chan TaskResponse, stop chan<- struct{}, err error) }
Client allows calls to a remote server.
type Execer ¶
type Execer interface {
Exec(ctx context.Context, request TaskRequest, client Client)
}
Execer is an interface that runs tasks. It should be passed as a parameter to Register method.
type ExecerWithResponder ¶
type ExecerWithResponder interface {
Exec(ctx context.Context, request TaskRequest, client ResponderClient)
}
ExecerWithResponder is an interface that runs tasks. It should be passed as a parameter to RegisterWithResponder method. The ResponderClient parameter can be used to send a response back to the caller.
type Responder ¶
type Responder interface { Respond(ctx context.Context, status string, data []byte) error RespondWithType(ctx context.Context, newType, status string, data []byte) error }
Responder is a simple interface to send a response. Value of the parameter status must not be an empty string.
type ResponderClient ¶
type Server ¶
type Server interface { // Register registers an Execer to run tasks for the provided task type. Register(t string, execer Execer) // RegisterWithResponder registers an ExecerWithResponder to run tasks for the provided task type. // The ExecerWithResponder implementation has ability to send messages back to the caller. RegisterWithResponder(t string, execer ExecerWithResponder) // RegisterCatchAll registers an ExecerWithResponder to run all tasks that are not already registered. RegisterCatchAll(execer ExecerWithResponder) }
Server allows objects that implement Execer interface to be registered to execute tasks.
type ServerClient ¶
type TaskRequest ¶
type TaskRequest struct { // ID is an id. Response message uses use the same ID as the request to which it's a response to. ID string // Type describes type of a task. Type string // Data holds arbitrary byte data payload. Data []byte }
TaskRequest contains information about a task that needs to executed.