processor.go 1.3 KB

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