message.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package model
  2. import "encoding/json"
  3. type Role string
  4. const (
  5. RoleProducer Role = "producer"
  6. RoleConsumer Role = "consumer"
  7. RoleController Role = "controller"
  8. )
  9. type Envelope struct {
  10. SchemaVersion int `json:"schemaVersion"`
  11. MessageID string `json:"messageId,omitempty"`
  12. Timestamp int64 `json:"timestamp"`
  13. Topic string `json:"topic"`
  14. Source Source `json:"source"`
  15. Target Target `json:"target"`
  16. Payload json.RawMessage `json:"payload"`
  17. }
  18. type Source struct {
  19. Kind Role `json:"kind"`
  20. ID string `json:"id"`
  21. Mode string `json:"mode,omitempty"`
  22. }
  23. type Target struct {
  24. ChannelID string `json:"channelId,omitempty"`
  25. DeviceID string `json:"deviceId,omitempty"`
  26. GroupID string `json:"groupId,omitempty"`
  27. }
  28. type ClientMessage struct {
  29. Type string `json:"type"`
  30. Role Role `json:"role,omitempty"`
  31. ChannelID string `json:"channelId,omitempty"`
  32. Token string `json:"token,omitempty"`
  33. Subscriptions []Subscription `json:"subscriptions,omitempty"`
  34. Envelope *Envelope `json:"envelope,omitempty"`
  35. }
  36. type Subscription struct {
  37. ChannelID string `json:"channelId,omitempty"`
  38. DeviceID string `json:"deviceId,omitempty"`
  39. GroupID string `json:"groupId,omitempty"`
  40. Topic string `json:"topic,omitempty"`
  41. }
  42. type ServerMessage struct {
  43. Type string `json:"type"`
  44. SessionID string `json:"sessionId,omitempty"`
  45. Error string `json:"error,omitempty"`
  46. Envelope *Envelope `json:"envelope,omitempty"`
  47. State json.RawMessage `json:"state,omitempty"`
  48. }
  49. type LatestState struct {
  50. DeviceID string `json:"deviceId"`
  51. GroupID string `json:"groupId,omitempty"`
  52. UpdatedAt int64 `json:"updatedAt"`
  53. Topics []string `json:"topics"`
  54. }