modify and add new fields for drivers

This commit is contained in:
Adrian Zuercher
2025-07-29 12:05:03 +02:00
parent 2d6db85b8c
commit eabac1b11b
5 changed files with 110 additions and 23 deletions

View File

@@ -3,23 +3,10 @@ package models
// collection of drivers ordered in map
type Drivers map[string]*Driver
// driver model
type Driver struct {
Type string `json:"type,omitempty"` // driver type name of driver in collection
Bus string `json:"bus"` // name of driver bus
Address uint `json:"address"` // address of bus
}
// returns a new collection of drivers
func NewDrivers() Drivers {
return make(Drivers)
}
// Add new driver to driver collection
// typ is the name of the driver in driver collection
func (d *Drivers) AddDriver(typ, bus string, address uint) {
(*d)[typ] = &Driver{
Bus: bus,
Address: address,
func (d *Drivers) AddDriver(typ string) *Driver {
if drv, ok := (*d)[typ]; ok {
return drv
}
(*d)[typ] = &Driver{Type: typ}
return (*d)[typ]
}