event.go 566 B

1234567891011121314151617181920212223242526272829
  1. package borealis
  2. import (
  3. "encoding/json"
  4. "reflect"
  5. "time"
  6. "github.com/segmentio/ksuid"
  7. )
  8. type Event struct {
  9. Type EventType `json:"type,string"`
  10. SequentialID uint64 `json:"sequential_id"`
  11. Timestamp time.Time `json:"timestamp"`
  12. UniqueID ksuid.KSUID `json:"unique_id"`
  13. Payload interface{} `json:"payload"`
  14. }
  15. func (event Event) Equal(other Event) bool {
  16. return reflect.DeepEqual(event, other)
  17. }
  18. func (event Event) JSON() string {
  19. output, err := json.Marshal(event)
  20. if err != nil {
  21. panic(err)
  22. }
  23. return string(output)
  24. }