mesg

package module
v0.0.0-...-e741021 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2019 License: Apache-2.0 Imports: 13 Imported by: 2

README

Documentation

Overview

Package mesg is a service client for mesg-core. For more information please visit https://mesg.com.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data interface{}

Data represents event data and output data of tasks.

type Dialer

type Dialer interface {
	Dial() (net.Conn, error)
}

Dialer describes a dialer implementation for network.

type Execution

type Execution struct {
	// ID is the execution id of task.
	ID string

	// Key is the name of task.
	Key string
	// contains filtered or unexported fields
}

Execution holds information about a Task execution.

func (*Execution) Data

func (e *Execution) Data(out interface{}) error

Data decodes task data input to out.

type Option

type Option func(*Service)

Option is the configuration func of Service.

func DialOption

func DialOption(dialer Dialer) Option

DialOption used to mock socket communication for unit testing.

func EndpointOption

func EndpointOption(address string) Option

EndpointOption receives the TCP endpoint of mesg-core.

func LogOutputOption

func LogOutputOption(out io.Writer) Option

LogOutputOption uses out as a log destination.

func TimeoutOption

func TimeoutOption(d time.Duration) Option

TimeoutOption receives d to use while dialing mesg-core and making requests.

func TokenOption

func TokenOption(token string) Option

TokenOption receives token which is the unique id of this service.

type Service

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

Service represents a MESG service.

func New

func New(options ...Option) (*Service, error)

New starts a new Service with options.

func (*Service) Close

func (s *Service) Close() error

Close gracefully stops listening for future task execution requests and waits current ones to complete before closing underlying connection.

func (*Service) Emit

func (s *Service) Emit(eventKey string, eventData Data) error

Emit emits a MESG event eventKey with given eventData.

func (*Service) Listen

func (s *Service) Listen(task Taskable, tasks ...Taskable) error

Listen listens requests for given tasks. It's a blocking call.

type Taskable

type Taskable interface {
	// Key returns the task key.
	Key() string

	// Execute called when a task execution request arrived with the same key
	// returned by Name().
	// outputKey is the output key and data is the output data of task.
	Execute(execution *Execution) (outputKey string, outputData Data)
}

Taskable represents implementation of task executor.

func Task

func Task(key string, handler func(*Execution) (outputKey string, outputData Data)) Taskable

Task creates an executable task for given task key, handler called when a matching task execution request arrived.

Directories

Path Synopsis
examples
Package mesgtest is a testing package for MESG service.
Package mesgtest is a testing package for MESG service.

Jump to

Keyboard shortcuts

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