add remove driver function
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package models
|
||||
|
||||
import "slices"
|
||||
|
||||
// driver model
|
||||
type Driver struct {
|
||||
Type string `json:"type"` // driver type name of driver in collection
|
||||
@@ -36,6 +38,38 @@ next:
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Driver) RemoveBus(bus *Bus) {
|
||||
for _, currentBus := range d.Buses {
|
||||
if currentBus.Name != bus.Name {
|
||||
continue
|
||||
}
|
||||
|
||||
currentBus.RemoveAddress(bus.Address...)
|
||||
if bus.Topic != nil {
|
||||
currentBus.RemoveSubscription(bus.Topic.Subscribe...)
|
||||
currentBus.RemovePublish(bus.Topic.Publish...)
|
||||
if len(currentBus.Address) == 0 {
|
||||
var remove bool = true
|
||||
if currentBus.Topic != nil {
|
||||
remove = len(currentBus.Topic.Subscribe) == 0 && len(currentBus.Topic.Publish) == 0
|
||||
}
|
||||
if remove {
|
||||
if len(d.Buses) == 1 {
|
||||
d.Buses = []*Bus{}
|
||||
return
|
||||
}
|
||||
for i, b := range d.Buses {
|
||||
if bus.Name == b.Name {
|
||||
d.Buses = slices.Delete(d.Buses, i, i+1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Driver) GetBus(name string) *Bus {
|
||||
for _, b := range d.Buses {
|
||||
if b.Name == name {
|
||||
|
Reference in New Issue
Block a user