events.go 411 B

123456789101112131415161718192021222324
  1. package pubsub
  2. import "context"
  3. type EventType string
  4. const (
  5. EventTypeCreated EventType = "created"
  6. EventTypeUpdated EventType = "updated"
  7. EventTypeDeleted EventType = "deleted"
  8. )
  9. type Event[T any] struct {
  10. Type EventType
  11. Payload T
  12. }
  13. type Subscriber[T any] interface {
  14. Subscribe(ctx context.Context) <-chan Event[T]
  15. }
  16. type Publisher[T any] interface {
  17. Publish(eventType EventType, payload T)
  18. }