You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
537 B

4 years ago
4 years ago
4 years ago
4 years ago
  1. package models
  2. import "strconv"
  3. type Event struct {
  4. Name string `json:"name"`
  5. Payload map[string]string `json:"payload,omitempty"`
  6. }
  7. func (e *Event) AddPayload(key, value string) {
  8. if e.Payload == nil {
  9. e.Payload = make(map[string]string, 8)
  10. }
  11. e.Payload[key] = value
  12. }
  13. func (e *Event) HasPayload(key string) bool {
  14. return e.Payload != nil && e.Payload[key] != ""
  15. }
  16. func BridgeConnectedEvent(bridge Bridge) Event {
  17. e := Event{Name: "BridgeConnected"}
  18. e.AddPayload("id", strconv.Itoa(bridge.ID))
  19. return e
  20. }