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,16 +40,19 @@ next:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) RemoveBus(bus *Bus) {
|
func (d *Driver) RemoveBuses(buses []*Bus) {
|
||||||
|
for _, bus := range buses {
|
||||||
for _, currentBus := range d.Buses {
|
for _, currentBus := range d.Buses {
|
||||||
if currentBus.Name != bus.Name {
|
if currentBus.Name != bus.Name {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
currentBus.RemoveAddress(bus.Address...)
|
currentBus.RemoveAddress(bus.Address...)
|
||||||
|
|
||||||
if bus.Topic != nil {
|
if bus.Topic != nil {
|
||||||
currentBus.RemoveSubscription(bus.Topic.Subscribe...)
|
currentBus.RemoveSubscription(bus.Topic.Subscribe...)
|
||||||
currentBus.RemovePublish(bus.Topic.Publish...)
|
currentBus.RemovePublish(bus.Topic.Publish...)
|
||||||
|
|
||||||
if len(currentBus.Address) == 0 {
|
if len(currentBus.Address) == 0 {
|
||||||
var remove bool = true
|
var remove bool = true
|
||||||
if currentBus.Topic != nil {
|
if currentBus.Topic != nil {
|
||||||
@@ -68,6 +73,7 @@ func (d *Driver) RemoveBus(bus *Bus) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) GetBus(name string) *Bus {
|
func (d *Driver) GetBus(name string) *Bus {
|
||||||
|
|||||||
@@ -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