1package pubsub
 2
 3import "context"
 4
 5const (
 6	CreatedEvent EventType = "created"
 7	UpdatedEvent EventType = "updated"
 8	DeletedEvent EventType = "deleted"
 9)
10
11type Suscriber[T any] interface {
12	Subscribe(context.Context) <-chan Event[T]
13}
14
15type (
16	// EventType identifies the type of event
17	EventType string
18
19	// Event represents an event in the lifecycle of a resource
20	Event[T any] struct {
21		Type    EventType `json:"type"`
22		Payload T         `json:"payload"`
23	}
24
25	Publisher[T any] interface {
26		Publish(EventType, T)
27	}
28)
29
30func (t EventType) MarshalText() ([]byte, error) {
31	return []byte(t), nil
32}
33
34func (t *EventType) UnmarshalText(data []byte) error {
35	*t = EventType(data)
36	return nil
37}