44 lines
942 B
Go
44 lines
942 B
Go
package models
|
|
|
|
// driver model
|
|
type Driver struct {
|
|
Type string `json:"type"` // driver type name of driver in collection
|
|
Buses map[string]*Bus `json:"buses"` // name of driver bus
|
|
}
|
|
|
|
func (d *Driver) AddNewBus(name string) *Bus {
|
|
if d.Buses == nil {
|
|
d.Buses = make(map[string]*Bus)
|
|
}
|
|
if b, ok := d.Buses[name]; ok {
|
|
return b
|
|
}
|
|
d.Buses[name] = &Bus{Name: name}
|
|
return d.Buses[name]
|
|
}
|
|
|
|
func (d *Driver) AddBuses(buses map[string]*Bus) {
|
|
if d.Buses == nil {
|
|
d.Buses = make(map[string]*Bus)
|
|
}
|
|
for key, newBus := range buses {
|
|
if currentBus, ok := d.Buses[key]; ok {
|
|
currentBus.AddAddress(newBus.Address...)
|
|
if newBus.Topic == nil {
|
|
continue
|
|
}
|
|
currentBus.AddSubscription(newBus.Topic.Subscribe...)
|
|
currentBus.AddPublish(newBus.Topic.Publish...)
|
|
continue
|
|
}
|
|
d.Buses[key] = newBus
|
|
}
|
|
}
|
|
|
|
func (d *Driver) GetBus(name string) *Bus {
|
|
if b, ok := d.Buses[name]; ok {
|
|
return b
|
|
}
|
|
return nil
|
|
}
|