liteproto

package
v0.0.0-...-10cdc12 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusSuccess = "success"
	StatusOK      = "ok"
	StatusError   = "error"
)

Variables

View Source
var ErrAlreadySubscribed = errors.New("subscription already exists for ID")

ErrAlreadySubscribed is returned by ResponseHandler when there is already a subscription to an ID.

View Source
var ErrNotSubscribed = errors.New("no subscription for ID")

ErrNotSubscribed is returned by ResponseHandler when there is no subscription to an ID.

View Source
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 ResponderClient interface {
	Client
	Responder
}

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 ServerClient interface {
	Server
	Client
}

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.

type TaskResponse

type TaskResponse struct {
	// ID is an id.
	ID string

	// Type describes type of a task.
	Type string

	// Status holds a status of a task ("success" or "error")
	Status string

	// Data holds arbitrary byte data payload.
	Data []byte
}

TaskResponse contains response of a task.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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