command.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package rest
  2. type IApplication interface {
  3. Executer(r IRequestIn) (IExecuter, bool)
  4. }
  5. type IApplicationStream interface {
  6. IApplication
  7. Connect() chan<- IStream
  8. }
  9. ///////////////////////////////////////////////
  10. type IValidator interface {
  11. Validate(r IRequestIn) IRequestOut
  12. }
  13. type IExecuter interface {
  14. Execute(r IRequestIn) IRequestOut
  15. }
  16. type ICommand interface {
  17. IValidator
  18. IExecuter
  19. }
  20. ///////////////////////////////////////////////
  21. func NewCommand(validator IValidator, executer IExecuter) *Command {
  22. return &Command{
  23. validator,
  24. executer,
  25. }
  26. }
  27. type Command struct {
  28. validator IValidator
  29. executer IExecuter
  30. }
  31. func (s *Command) Validate(r IRequestIn) IRequestOut {
  32. return s.validator.Validate(r)
  33. }
  34. func (s *Command) Execute(r IRequestIn) IRequestOut {
  35. return s.executer.Execute(r)
  36. }
  37. ///////////////////////////////////////////////
  38. func NewValidator(method func(r IRequestIn) IRequestOut) *Validator {
  39. return &Validator{
  40. method,
  41. }
  42. }
  43. type Validator struct {
  44. method func(r IRequestIn) IRequestOut
  45. }
  46. func (s *Validator) Validate(r IRequestIn) IRequestOut {
  47. return s.method(r)
  48. }
  49. ///////////////////////////////////////////////
  50. func NewExecuter(method func(r IRequestIn) IRequestOut) *Executer {
  51. return &Executer{
  52. method,
  53. }
  54. }
  55. type Executer struct {
  56. method func(r IRequestIn) IRequestOut
  57. }
  58. func (s *Executer) Execute(r IRequestIn) IRequestOut {
  59. return s.method(r)
  60. }