forked from jasonfriedland/go-guerrilla
/
processor.go
51 lines (40 loc) · 1.34 KB
/
processor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package backends
import (
"github.com/artpar/go-guerrilla/mail"
)
type SelectTask int
const (
TaskSaveMail SelectTask = iota
TaskValidateRcpt
)
func (o SelectTask) String() string {
switch o {
case TaskSaveMail:
return "save mail"
case TaskValidateRcpt:
return "validate recipient"
}
return "[unnamed task]"
}
var BackendResultOK = NewResult("200 OK")
// Our processor is defined as something that processes the envelope and returns a result and error
type Processor interface {
Process(*mail.Envelope, SelectTask) (Result, error)
}
// Signature of Processor
type ProcessWith func(*mail.Envelope, SelectTask) (Result, error)
// Make ProcessWith will satisfy the Processor interface
func (f ProcessWith) Process(e *mail.Envelope, task SelectTask) (Result, error) {
// delegate to the anonymous function
return f(e, task)
}
// DefaultProcessor is a undecorated worker that does nothing
// Notice DefaultProcessor has no knowledge of the other decorators that have orthogonal concerns.
type DefaultProcessor struct{}
// do nothing except return the result
// (this is the last call in the decorator stack, if it got here, then all is good)
func (w DefaultProcessor) Process(e *mail.Envelope, task SelectTask) (Result, error) {
return BackendResultOK, nil
}
// if no processors specified, skip operation
type NoopProcessor struct{ DefaultProcessor }