service

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package service 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 Dialer

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

Dialer describes a dialer implementation for network.

type Execution

type Execution struct {
	// Hash is the execution id of task.
	Hash 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 interface{}) 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().
	Execute(execution *Execution) (interface{}, error)
}

Taskable represents implementation of task executor.

func Task

func Task(key string, handler func(*Execution) (interface{}, error)) Taskable

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

Directories

Path Synopsis
examples
Package servicetest is a testing package for MESG service.
Package servicetest 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