Documentation
¶
Index ¶
- Constants
- Variables
- func Equal(v1, v2 *Message) bool
- type Controller
- func (c *Controller) Connect(connection net.Conn) <-chan bool
- func (c *Controller) Disconnect()
- func (c *Controller) Pub(command *types.Command, receiverID uuid.UUID)
- func (c *Controller) PubMessage(message *Message, topics ...string)
- func (c *Controller) Reply(request *Message, replyType types.CommandType, replyContent interface{})
- func (c *Controller) Shutdown()
- func (c *Controller) Start(h Handler)
- func (c *Controller) Sub(topics ...string) chan interface{}
- func (c *Controller) SubOnce(topics ...string) chan interface{}
- type Handler
- type Message
- type Remote
- type StatusHolder
Constants ¶
const BufferSize = 10
BufferSize is the size of channel buffers
const IncomingMessage = "in"
IncomingMessage is a message that comes from remote peers
const MaxIdleTime = 5 * time.Minute
MaxIdleTime is the maximum time to wait before closing a connection for inactivity
const OutgoingMessage = "out"
OutgoingMessage is the signature a message needs to go to remote peers
const WriteTimeout = 1 * time.Minute
WriteTimeout defines the time after which a write operation is considered failed
Variables ¶
var LoopbackID = uuid.Nil
LoopbackID is the id internal only messages are sent to
Functions ¶
Types ¶
type Controller ¶
func (*Controller) Connect ¶
func (c *Controller) Connect(connection net.Conn) <-chan bool
Connect tries to brign up the remoe connection it returns a channel that gets closed when the connection goes down
func (*Controller) Disconnect ¶
func (c *Controller) Disconnect()
Disconnect disconnects the remote connection (if any)
func (*Controller) Pub ¶
func (c *Controller) Pub(command *types.Command, receiverID uuid.UUID)
Pub publishes a Message composed by the given Command
func (*Controller) PubMessage ¶
func (c *Controller) PubMessage(message *Message, topics ...string)
PubMessage publishes a Message
func (*Controller) Reply ¶
func (c *Controller) Reply(request *Message, replyType types.CommandType, replyContent interface{})
Reply sends back a reply message
func (*Controller) Shutdown ¶
func (c *Controller) Shutdown()
Shutdown disconnects and turns off every handler
func (*Controller) Start ¶
func (c *Controller) Start(h Handler)
Start starts every registered handler
func (*Controller) Sub ¶
func (c *Controller) Sub(topics ...string) chan interface{}
Sub Subscribes to one or more message types
func (*Controller) SubOnce ¶
func (c *Controller) SubOnce(topics ...string) chan interface{}
SubOnce subscribes to the first event of one of the given topics, then it deletes the subscription
type Handler ¶
type Handler interface {
fmt.Stringer
Run(controller *Controller)
}
Handler is the interface that handles network messages and optionally can return a reply
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
func NewMessage ¶
NewMessage creates a new message
func ParseMessage ¶
ParseMessage handles incoming data and creates a Message object
func (*Message) ReceiverUUID ¶
ReceiverUUID returns the receiver identity
func (*Message) SenderUUID ¶
SenderUUID returns the sender identity
type Remote ¶
type Remote struct {
Closed chan bool
// contains filtered or unexported fields
}
Remote represents a remote endpoint, data can be sent or received through InBuffer and OutBuffer
type StatusHolder ¶
type StatusHolder struct {
// contains filtered or unexported fields
}
StatusHolder is a struct that stores status of an handler that needs to trigger status changes when something happens
func NewStatusHolder ¶
func NewStatusHolder(moduleName string) *StatusHolder
NewStatusHolder creates a StatusHolder
func (*StatusHolder) Edit ¶
func (s *StatusHolder) Edit(controller *Controller, editFunction func(interface{}) interface{})
Edit the current status via editFunction
func (*StatusHolder) Set ¶
func (s *StatusHolder) Set(status interface{}, controller *Controller)
Set stores the status and emits it if it is changed