package appcontext import ( "encoding/json" "time" "github.com/AFASystems/presence/internal/pkg/kafkaclient" ) type BaseHealth struct { Uptime time.Duration `json:"uptime"` ActiveReaders []string `json:"activeReaders" gorm:"type:jsonb"` ActiveWriters []string `json:"activeWriters" gorm:"type:jsonb"` ActiveBeacons []string `json:"activeBeacons" gorm:"type:jsonb"` } type DecoderHealth struct { BaseHealth // current active configs ? dont know yet how } type LocationHealth struct { BaseHealth ActiveSettings []Settings `json:"activeSettings" gorm:"type:jsonb"` } type BridgeHealth struct { BaseHealth } type Health struct { ID string `json:"id" gorm:"primaryKey"` Location LocationHealth `gorm:"embedded;embeddedPrefix:loc_"` Decoder DecoderHealth `gorm:"embedded;embeddedPrefix:dec_"` Bridge BridgeHealth `gorm:"embedded;embeddedPrefix:brg_"` } func (b *BaseHealth) GetUptime(startTime time.Time) { b.Uptime = time.Since(startTime) } func (b *BaseHealth) GetActiveReaders(m *kafkaclient.KafkaManager) { b.ActiveReaders = m.GetReaders() } func (b *BaseHealth) GetActiveWriters(m *kafkaclient.KafkaManager) { b.ActiveWriters = m.GetWriters() } func (b *BaseHealth) GetActiveBeacons(m *AppState) { beacons := m.GetAllBeacons() for beacon := range beacons { b.ActiveBeacons = append(b.ActiveBeacons, beacon) } } func (d *DecoderHealth) Marshal() ([]byte, error) { return json.Marshal(d) } func (l *LocationHealth) Marshal() ([]byte, error) { return json.Marshal(l) } func (b *BridgeHealth) Marshal() ([]byte, error) { return json.Marshal(b) }