package event import ( "encoding/json" ) // Event represents the PG notification payload. type Event struct { Channel string `json:"channel"` Operation interface{} `json:"operation"` ClusterInfraClusterEdgeID interface{} `json:"cluster_infra_cluster_edge_id"` BannerEdgeID interface{} `json:"banner_edge_id"` Data interface{} `json:"data"` } // New creates a new database event instance. func New() *Event { return &Event{} } // Unmarshal unmarshals the pg notification string into a database event and sets the channel name. func (e *Event) Unmarshal(channel, event string) (*Event, error) { err := json.Unmarshal([]byte(event), e) e.Channel = channel return e, err } // ToByte marshals a database event so it can be sent via pubsub. func (e *Event) ToByte() ([]byte, error) { return json.Marshal(e) }