feudal/message/envelope.go
Matthew Rich c545200ade
Some checks failed
Lint / golangci-lint (push) Failing after 9m57s
Declarative Tests / test (push) Failing after 10s
add initial commit
2024-04-04 12:43:46 -07:00

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 }
}