mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-01-08 17:51:57 +00:00
Make the queue aware of local and remote couriers
The routing courier is a nice idea in theory, but at least for now, we want the queue to be aware of when a destination is local so we can implement differentiated logic. This may change in the future, though, but at the moment it's not clear that the abstractions will be worth it. So this patch removes it, and makes the queue do the routing. There is no difference in how the two are handled yet, those will come in subsequent patches.
This commit is contained in:
@@ -1,28 +1,9 @@
|
||||
// Package courier implements various couriers for delivering messages.
|
||||
package courier
|
||||
|
||||
import "blitiri.com.ar/go/chasquid/internal/envelope"
|
||||
|
||||
// Courier delivers mail to a single recipient.
|
||||
// It is implemented by different couriers, for both local and remote
|
||||
// recipients.
|
||||
type Courier interface {
|
||||
Deliver(from string, to string, data []byte) error
|
||||
}
|
||||
|
||||
// Router decides if the destination is local or remote, and delivers
|
||||
// accordingly.
|
||||
type Router struct {
|
||||
Local Courier
|
||||
Remote Courier
|
||||
LocalDomains map[string]bool
|
||||
}
|
||||
|
||||
func (r *Router) Deliver(from string, to string, data []byte) error {
|
||||
d := envelope.DomainOf(to)
|
||||
if r.LocalDomains[d] {
|
||||
return r.Local.Deliver(from, to, data)
|
||||
} else {
|
||||
return r.Remote.Deliver(from, to, data)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user