Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c15710ddec | ||
|
|
2924d95f4b |
@@ -1,6 +1,8 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import "slices"
|
import (
|
||||||
|
"slices"
|
||||||
|
)
|
||||||
|
|
||||||
// driver model
|
// driver model
|
||||||
type Driver struct {
|
type Driver struct {
|
||||||
@@ -38,34 +40,38 @@ next:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) RemoveBus(bus *Bus) {
|
func (d *Driver) RemoveBuses(buses []*Bus) {
|
||||||
for _, currentBus := range d.Buses {
|
for _, bus := range buses {
|
||||||
if currentBus.Name != bus.Name {
|
for _, currentBus := range d.Buses {
|
||||||
continue
|
if currentBus.Name != bus.Name {
|
||||||
}
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
currentBus.RemoveAddress(bus.Address...)
|
currentBus.RemoveAddress(bus.Address...)
|
||||||
if bus.Topic != nil {
|
|
||||||
currentBus.RemoveSubscription(bus.Topic.Subscribe...)
|
if bus.Topic != nil {
|
||||||
currentBus.RemovePublish(bus.Topic.Publish...)
|
currentBus.RemoveSubscription(bus.Topic.Subscribe...)
|
||||||
if len(currentBus.Address) == 0 {
|
currentBus.RemovePublish(bus.Topic.Publish...)
|
||||||
var remove bool = true
|
|
||||||
if currentBus.Topic != nil {
|
if len(currentBus.Address) == 0 {
|
||||||
remove = len(currentBus.Topic.Subscribe) == 0 && len(currentBus.Topic.Publish) == 0
|
var remove bool = true
|
||||||
}
|
if currentBus.Topic != nil {
|
||||||
if remove {
|
remove = len(currentBus.Topic.Subscribe) == 0 && len(currentBus.Topic.Publish) == 0
|
||||||
if len(d.Buses) == 1 {
|
|
||||||
d.Buses = []*Bus{}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
for i, b := range d.Buses {
|
if remove {
|
||||||
if bus.Name == b.Name {
|
if len(d.Buses) == 1 {
|
||||||
d.Buses = slices.Delete(d.Buses, i, i+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
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,3 +19,17 @@ func (d *Drivers) AddDriver(drv *Driver) {
|
|||||||
}
|
}
|
||||||
(*d)[drv.Type] = drv
|
(*d)[drv.Type] = drv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Drivers) RemoveDriver(drv *Driver) {
|
||||||
|
if driver, ok := (*d)[drv.Type]; ok {
|
||||||
|
driver.RemoveBuses(drv.Buses)
|
||||||
|
if len(driver.Buses) == 1 {
|
||||||
|
if len(driver.Buses[0].Address) == 0 && driver.Buses[0].Topic == nil {
|
||||||
|
(*d)[drv.Type] = &Driver{}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(*d)[drv.Type] = driver
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import "slices"
|
import (
|
||||||
|
"slices"
|
||||||
|
)
|
||||||
|
|
||||||
// topic model
|
// topic model
|
||||||
type Topic struct {
|
type Topic struct {
|
||||||
@@ -33,6 +35,7 @@ func (t *Topic) RemoveSubscription(subs ...string) {
|
|||||||
t.Subscribe = []string{}
|
t.Subscribe = []string{}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, toDelete := range subs {
|
for _, toDelete := range subs {
|
||||||
for i, a := range t.Subscribe {
|
for i, a := range t.Subscribe {
|
||||||
if a == toDelete {
|
if a == toDelete {
|
||||||
|
|||||||
Reference in New Issue
Block a user