32 lines
618 B
Go
32 lines
618 B
Go
package models
|
|
|
|
import "slices"
|
|
|
|
// bus model
|
|
type Bus struct {
|
|
Name string `json:"name,omitemtpy"`
|
|
Address []uint `json:"address,omitemtpy"` // address of bus
|
|
Topic *Topic `json:"topic,omitemtpy"` // address of bus
|
|
}
|
|
|
|
func (b *Bus) AddAddress(address uint) {
|
|
if !slices.Contains(b.Address, address) {
|
|
b.Address = append(b.Address, address)
|
|
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)
|
|
}
|