package repository type IBP struct { Spk *IBPRefMap Emp *IBPRefMap } func NewIBP() *IBP { return &IBP{ Spk: &IBPRefMap{ buttonMap: make(map[string]*Button), relayMap: make(map[string]*Relay), alarmMap: make(map[string]*Alarm), }, Emp: &IBPRefMap{ buttonMap: make(map[string]*Button), relayMap: make(map[string]*Relay), alarmMap: make(map[string]*Alarm), }, } } type IBPRefMap struct { buttonMap map[string]*Button relayMap map[string]*Relay alarmMap map[string]*Alarm } func (ibp *IBPRefMap) AddButton(btn *Button) { ibp.buttonMap[btn.Id()] = btn } func (ibp *IBPRefMap) AddRelay(relay *Relay) { ibp.relayMap[relay.Id()] = relay } func (ibp *IBPRefMap) AddAlarm(fmq *Alarm) { ibp.alarmMap[fmq.Id()] = fmq } func (ibp *IBPRefMap) Buttons() []*Button { var buttons []*Button for _, b := range ibp.buttonMap { buttons = append(buttons, b) } return buttons } func (ibp *IBPRefMap) Relays() []*Relay { var relays []*Relay for _, b := range ibp.relayMap { relays = append(relays, b) } return relays } func (ibp *IBPRefMap) Alarms() []*Alarm { var alarms []*Alarm for _, b := range ibp.alarmMap { alarms = append(alarms, b) } return alarms }