49 lines
804 B
Go
49 lines
804 B
Go
package message
|
|
|
|
import "git.sr.ht/~cco/go-scopes/lib"
|
|
|
|
// Message implementation(s)
|
|
|
|
type strMessage string
|
|
|
|
func (msg strMessage) Action() string {
|
|
return string(msg)
|
|
}
|
|
|
|
func (msg strMessage) Sender() lib.Address {
|
|
return nil
|
|
}
|
|
|
|
func StrMessage(action string) strMessage {
|
|
return strMessage(action)
|
|
}
|
|
|
|
var Quit = StrMessage("quit")
|
|
|
|
// Address implementation
|
|
|
|
type address struct {
|
|
service string
|
|
}
|
|
|
|
func (addr *address) Service() string {
|
|
return addr.service
|
|
}
|
|
|
|
func (addr *address) Send(ctx lib.Context, msg lib.Message) {
|
|
Send(ctx, addr, msg)
|
|
}
|
|
|
|
func SimpleAddress(srv string) *address {
|
|
return &address{
|
|
service: srv,
|
|
}
|
|
}
|
|
|
|
// public functions
|
|
|
|
func Send(ctx lib.Context, addr lib.Address, msg lib.Message) {
|
|
if srv, ok := ctx.Services()[addr.Service()]; ok {
|
|
srv.Mailbox() <- msg
|
|
}
|
|
}
|