Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

68 rindas
1.6 KiB

  1. package appcontext
  2. import (
  3. "encoding/json"
  4. "time"
  5. "github.com/AFASystems/presence/internal/pkg/kafkaclient"
  6. )
  7. type BaseHealth struct {
  8. Uptime time.Duration `json:"uptime"`
  9. ActiveReaders []string `json:"activeReaders" gorm:"type:jsonb"`
  10. ActiveWriters []string `json:"activeWriters" gorm:"type:jsonb"`
  11. ActiveBeacons []string `json:"activeBeacons" gorm:"type:jsonb"`
  12. }
  13. type DecoderHealth struct {
  14. BaseHealth
  15. // current active configs ? dont know yet how
  16. }
  17. type LocationHealth struct {
  18. BaseHealth
  19. ActiveSettings []Settings `json:"activeSettings" gorm:"type:jsonb"`
  20. }
  21. type BridgeHealth struct {
  22. BaseHealth
  23. }
  24. type Health struct {
  25. ID string `json:"id" gorm:"primaryKey"`
  26. Location LocationHealth `gorm:"embedded;embeddedPrefix:loc_"`
  27. Decoder DecoderHealth `gorm:"embedded;embeddedPrefix:dec_"`
  28. Bridge BridgeHealth `gorm:"embedded;embeddedPrefix:brg_"`
  29. }
  30. func (b *BaseHealth) GetUptime(startTime time.Time) {
  31. b.Uptime = time.Since(startTime)
  32. }
  33. func (b *BaseHealth) GetActiveReaders(m *kafkaclient.KafkaManager) {
  34. b.ActiveReaders = m.GetReaders()
  35. }
  36. func (b *BaseHealth) GetActiveWriters(m *kafkaclient.KafkaManager) {
  37. b.ActiveWriters = m.GetWriters()
  38. }
  39. func (b *BaseHealth) GetActiveBeacons(m *AppState) {
  40. beacons := m.GetAllBeacons()
  41. for beacon := range beacons {
  42. b.ActiveBeacons = append(b.ActiveBeacons, beacon)
  43. }
  44. }
  45. func (d *DecoderHealth) Marshal() ([]byte, error) {
  46. return json.Marshal(d)
  47. }
  48. func (l *LocationHealth) Marshal() ([]byte, error) {
  49. return json.Marshal(l)
  50. }
  51. func (b *BridgeHealth) Marshal() ([]byte, error) {
  52. return json.Marshal(b)
  53. }