...

Source file src/edge-infra.dev/pkg/edge/lighthouse/event/event.go

Documentation: edge-infra.dev/pkg/edge/lighthouse/event

     1  package event
     2  
     3  import (
     4  	"encoding/json"
     5  )
     6  
     7  // Event represents the PG notification payload.
     8  type Event struct {
     9  	Channel                   string      `json:"channel"`
    10  	Operation                 interface{} `json:"operation"`
    11  	ClusterInfraClusterEdgeID interface{} `json:"cluster_infra_cluster_edge_id"`
    12  	BannerEdgeID              interface{} `json:"banner_edge_id"`
    13  	Data                      interface{} `json:"data"`
    14  }
    15  
    16  // New creates a new database event instance.
    17  func New() *Event {
    18  	return &Event{}
    19  }
    20  
    21  // Unmarshal unmarshals the pg notification string into a database event and sets the channel name.
    22  func (e *Event) Unmarshal(channel, event string) (*Event, error) {
    23  	err := json.Unmarshal([]byte(event), e)
    24  	e.Channel = channel
    25  	return e, err
    26  }
    27  
    28  // ToByte marshals a database event so it can be sent via pubsub.
    29  func (e *Event) ToByte() ([]byte, error) {
    30  	return json.Marshal(e)
    31  }
    32  

View as plain text