core: github.com/mesg-foundation/core/client/service Index | Files | Directories

package service

import "github.com/mesg-foundation/core/client/service"

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

Index

Package Files

dialer.go execution.go service.go task.go

type Dialer Uses

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

Dialer describes a dialer implementation for network.

type Execution Uses

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 Uses

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

Data decodes task data input to out.

type Option Uses

type Option func(*Service)

Option is the configuration func of Service.

func DialOption Uses

func DialOption(dialer Dialer) Option

DialOption used to mock socket communication for unit testing.

func EndpointOption Uses

func EndpointOption(address string) Option

EndpointOption receives the TCP endpoint of mesg-core.

func LogOutputOption Uses

func LogOutputOption(out io.Writer) Option

LogOutputOption uses out as a log destination.

func TimeoutOption Uses

func TimeoutOption(d time.Duration) Option

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

func TokenOption Uses

func TokenOption(token string) Option

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

type Service Uses

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

Service represents a MESG service.

func New Uses

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

New starts a new Service with options.

func (*Service) Close Uses

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 Uses

func (s *Service) Emit(eventKey string, eventData interface{}) error

Emit emits a MESG event eventKey with given eventData.

func (*Service) Listen Uses

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

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

type Taskable Uses

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 Uses

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

PathSynopsis
servicetestPackage servicetest is a testing package for MESG service.

Package service imports 14 packages (graph) and is imported by 1 packages. Updated 2019-06-25. Refresh now. Tools for package owners.