modify and add new fields for drivers
This commit is contained in:
31
models/bus.go
Normal file
31
models/bus.go
Normal file
@@ -0,0 +1,31 @@
|
||||
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)
|
||||
}
|
Reference in New Issue
Block a user