package repository type IBP struct { Spk *IBPRefMap Emp *IBPRefMap } func NewIBP() *IBP { return &IBP{ Spk: newIBPRefMap(), Emp: newIBPRefMap(), } } type IBPRefMap struct { buttonMap map[string]*Button relayMap map[string]*Relay alarmMap map[string]*Alarm lightMap map[string]*Light keyMap map[string]*Key } func newIBPRefMap() *IBPRefMap { return &IBPRefMap{ buttonMap: make(map[string]*Button), relayMap: make(map[string]*Relay), alarmMap: make(map[string]*Alarm), lightMap: make(map[string]*Light), keyMap: make(map[string]*Key), } } 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) AddLight(light *Light) { ibp.lightMap[light.Id()] = light } func (ibp *IBPRefMap) AddAlarm(fmq *Alarm) { ibp.alarmMap[fmq.Id()] = fmq } func (ibp *IBPRefMap) AddKey(key *Key) { ibp.keyMap[key.Id()] = key } 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 } func (ibp *IBPRefMap) Lights() []*Light { var lights []*Light for _, b := range ibp.lightMap { lights = append(lights, b) } return lights } func (ibp *IBPRefMap) Keys() []*Key { var keys []*Key for _, b := range ibp.keyMap { keys = append(keys, b) } return keys }