37 lines
658 B
Go
37 lines
658 B
Go
package models
|
|
|
|
import "slices"
|
|
|
|
// bus model
|
|
type Bus struct {
|
|
Name string `json:"name"`
|
|
Address []uint `json:"address,omitempty"` // address of bus
|
|
Topic *Topic `json:"topic,omitempty"` // address of bus
|
|
}
|
|
|
|
func (b *Bus) AddAddress(address ...uint) {
|
|
for _, a := range address {
|
|
if slices.Contains(b.Address, a) {
|
|
continue
|
|
}
|
|
b.Address = append(b.Address, a)
|
|
slices.Sort(b.Address)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (b *Bus) AddSubscription(sub ...string) {
|
|
if b.Topic == nil {
|
|
b.Topic = &Topic{}
|
|
}
|
|
b.Topic.AddSubscription(sub...)
|
|
}
|
|
|
|
func (b *Bus) AddPublish(pub ...string) {
|
|
if b.Topic == nil {
|
|
b.Topic = &Topic{}
|
|
}
|
|
b.Topic.AddPublish(pub...)
|
|
}
|