event.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * ECAL
  3. *
  4. * Copyright 2020 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the MIT
  7. * License, If a copy of the MIT License was not distributed with this
  8. * file, You can obtain one at https://opensource.org/licenses/MIT.
  9. */
  10. package engine
  11. import (
  12. "fmt"
  13. "strings"
  14. "devt.de/krotik/common/stringutil"
  15. )
  16. /*
  17. Event data structure
  18. */
  19. type Event struct {
  20. name string // Name of the event
  21. kind []string // Kind of the event (dot notation expressed as array)
  22. state map[interface{}]interface{} // Event state
  23. }
  24. /*
  25. NewEvent returns a new event object.
  26. */
  27. func NewEvent(name string, kind []string, state map[interface{}]interface{}) *Event {
  28. return &Event{name, kind, state}
  29. }
  30. /*
  31. Name returns the event name.
  32. */
  33. func (e *Event) Name() string {
  34. return e.name
  35. }
  36. /*
  37. Kind returns the event kind.
  38. */
  39. func (e *Event) Kind() []string {
  40. return e.kind
  41. }
  42. /*
  43. State returns the event state.
  44. */
  45. func (e *Event) State() map[interface{}]interface{} {
  46. return e.state
  47. }
  48. func (e *Event) String() string {
  49. return fmt.Sprintf("Event: %v %v %v", e.name, strings.Join(e.kind, "."),
  50. stringutil.ConvertToString(e.state))
  51. }