50 lines
1021 B
Go
50 lines
1021 B
Go
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
package message;
|
|
|
|
import (
|
|
"feudal/identity"
|
|
)
|
|
|
|
type Envelope interface {
|
|
Body() interface{}
|
|
Sender() Sender
|
|
Receiver() Receiver
|
|
}
|
|
|
|
type Handler interface {
|
|
Handle(m Envelope)
|
|
}
|
|
|
|
type Receiver interface {
|
|
identity.Addresser
|
|
Receive(m Envelope)
|
|
}
|
|
|
|
type Sender interface {
|
|
identity.Addresser
|
|
Send(m Envelope)
|
|
}
|
|
|
|
type AbstractEnvelope struct {
|
|
body interface{}
|
|
sender Sender
|
|
receiver Receiver
|
|
}
|
|
|
|
func (e *AbstractEnvelope) Body() interface{} { return e.body }
|
|
func (e *AbstractEnvelope) Sender() Sender { return e.sender }
|
|
func (e *AbstractEnvelope) Receiver() Receiver { return e.receiver }
|
|
|
|
func New(b interface{}, s Sender) Envelope {
|
|
return &AbstractEnvelope{ body: b, sender: s }
|
|
}
|
|
|
|
func NewAnonymous(b interface{}) Envelope {
|
|
return &AbstractEnvelope{ body: b, sender: nil }
|
|
}
|
|
|
|
func To(b interface{}, from Sender, to Receiver) Envelope {
|
|
return &AbstractEnvelope{ body: b, sender: from, receiver: to }
|
|
}
|