Documentation
¶
Index ¶
Constants ¶
const (
DefaultMsgType string = "grav.default"
)
DefaultMsgType and other represent message consts
Variables ¶
var ErrMsgNotWanted = errors.New("message not wanted")
ErrMsgNotWanted is used by WaitOn to determine if the current message is what's being waited on
Functions ¶
This section is empty.
Types ¶
type Grav ¶
type Grav struct { GroupName string // contains filtered or unexported fields }
Grav represents a Grav message bus instance
type Message ¶ added in v0.0.3
type Message interface { // Unique ID for this message UUID() string // ID of the parent event or request, such as HTTP request ParentID() string // The UUID of the message being responded to, if any ResponseTo() string // Type of message (application-specific) Type() string // Time the message was sent Timestamp() time.Time // Raw data of message Data() []byte // Unmarshal the message's data into a struct UnmarshalData(interface{}) error // Marshal the message itself to encoded bytes (JSON or otherwise) Marshal() ([]byte, error) // Unmarshal encoded Message into object Unmarshal([]byte) error }
Message represents a message
func MsgFromBytes ¶ added in v0.0.3
MsgFromBytes returns a default _message that has been unmarshalled from bytes. Should only be used if the default _message type is being used.
func MsgFromRequest ¶ added in v0.0.3
MsgFromRequest extracts an encoded Message from an HTTP request
func NewMsgResponseTo ¶ added in v0.0.3
NewMsgResponseTo creates a new message in response to a previous message
func NewMsgWithParentID ¶ added in v0.0.3
NewMsgWithParentID returns a new message with the provided parent ID
type MsgChan ¶ added in v0.0.3
type MsgChan chan Message
MsgChan is a channel that accepts a message
type MsgFunc ¶ added in v0.0.3
MsgFunc is a callback function that accepts a message and returns an error
type Pod ¶ added in v0.0.3
Pod is a connection to Grav Pods are bi-directional. Messages can be sent to them from the bus, and they can be used to send messages to the bus. Pods are meant to be extremely lightweight with no persistence they are meant to quickly and immediately route a message between its owner and the Bus. The Bus is responsible for any "smarts". Messages coming from the bus are filtered using the pod's messageFilter, which is configurable by the caller.
func (Pod) FilterType ¶ added in v0.0.3
func (Pod) FilterUUID ¶ added in v0.0.3
FilterUUID likely should not be used in normal cases, it adds a message UUID to the pod's filter.
func (*Pod) On ¶ added in v0.0.3
On sets the function to be called whenever this pod recieves a message from the bus. If nil is passed, the pod will ignore all messages. Calling On multiple times causes the function to be overwritten. To recieve using two different functions, create two pods.
func (*Pod) OnType ¶ added in v0.0.3
OnType sets the function to be called whenever this pod recieves a message and sets the pod's filter to only include certain message types
func (*Pod) WaitOn ¶ added in v0.0.3
WaitOn takes a function to be called whenever this pod recieves a message and blocks until that function returns something other than ErrMsgNotWanted. WaitOn should be used if there is a need to wait for a particular message. When the onFunc returns something other than ErrMsgNotWanted (such as nil or a different error), WaitOn will return and set the onFunc to nil. If an error other than ErrMsgNotWanted is returned from the onFunc, it will be propogated to the caller.