package models import "strconv" type Event struct { Name string `json:"name"` Payload map[string]string `json:"payload,omitempty"` } func (e *Event) AddPayload(key, value string) { if e.Payload == nil { e.Payload = make(map[string]string, 8) } e.Payload[key] = value } func (e *Event) HasPayload(key string) bool { return e.Payload != nil && e.Payload[key] != "" } var ( ENBridgeConnected = "BridgeConnected" ENBridgeDisconnected = "BridgeDisconnected" ENButtonPressed = "ButtonPressed" ENSensorPresenceStarted = "SensorPresenceStart" ENSensorPresenceEnded = "SensorPresenceEnd" ) func BridgeConnectedEvent(bridge Bridge) Event { e := Event{Name: ENBridgeConnected} e.AddPayload("bridgeId", strconv.Itoa(bridge.ID)) return e } func BridgeDisconnectedEvent(bridge Bridge) Event { e := Event{Name: ENBridgeDisconnected} e.AddPayload("bridgeId", strconv.Itoa(bridge.ID)) return e }