handler

package
v5.10.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: MIT, MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MessageHandler

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

A MessageHandler is responsible for routing messages of a set of types to their associated handler functions.

func NewMessageHandler

func NewMessageHandler() *MessageHandler

NewMessageHandler initializes and returns a pointer to a new MessageHandler.

func (*MessageHandler) AddHandler

func (h *MessageHandler) AddHandler(msgType string, handlerFunc MessageHandlerFunc)

AddHandler is used to register a MessageHandlerFunc for a given message type. This currently on supports a single handler for each message type. Subsequent calls to AddHandler will replace the current handler for a given message type. Last write wins.

func (*MessageHandler) Handle

func (h *MessageHandler) Handle(ctx context.Context, msgType string, payload []byte) error

Handle is used to dispatch a message of msgType type with a byte-array payload. This will return an error if the handler function returns an error or if there is no handler for a given message type.

type MessageHandlerFunc

type MessageHandlerFunc func(ctx context.Context, payload []byte) error

MessageHandlerFunc is a function accepting a byte array message payload that returns an optional error.

Jump to

Keyboard shortcuts

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