Guest User

Untitled

a guest
Dec 11th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. type AccountAggregate struct {
  2. cmdHandlers map[string]CommandHandler
  3. evHandlers map[string]EventHandler
  4. }
  5. func NewAccountAggregate() Aggregate {
  6. a := &AccountAggregate{}
  7. a.cmdHandlers = map[string]CommandHandler{
  8. "CreateAccount": a.createAccount,
  9. }
  10. a.evHandlers = map[string]EventHandler{
  11. "AccountCreated": a.onAccountCreated,
  12. }
  13. return a
  14. }
  15. func (a *AccountAggregate) createAccount(cmd Command) error {
  16. ev := Event{"AccountCreated", cmd.Payload}
  17. a.Causes(ev)
  18. return nil
  19. }
  20. func (a *AccountAggregate) onAccountCreated(ev Event) {
  21. // persisting of data
  22. }
  23. func (a *AccountAggregate) Load(events []Event) { … }
  24. func (a *AccountAggregate) Process(cmd Command) error { … }
  25. func (a *AccountAggregate) Causes(ev Event) { … }
Add Comment
Please, Sign In to add comment