package models import "github.com/google/uuid" // Set model type Set struct { Uuid uuid.UUID `json:"uuid,omitempty"` // universally unique identifier Path string `json:"path"` // dbm path Driver *Driver `json:"driver,omitempty"` // assign new driver Drivers *Drivers `json:"drivers,omitempty"` // assigned drivers Type Type `json:"type,omitempty"` // dbm datatype Value any `json:"value,omitempty"` // dbm value Rights Rights `json:"rights,omitempty"` // dbm read /write rights Create bool `json:"create,omitempty"` // dbm create new datapoint HasChild bool `json:"hasChild,omitempty"` // inidicates path has children Updated bool `json:"-"` } // sets value and path func (s *Set) ValueByPath(path string, value any) { s.Path = path s.Value = value } // sets value and uuid func (s *Set) ValueByUuid(uid string, value any) { s.Uuid = uuid.MustParse(uid) s.Value = value } // sets new datapoint with given parameters func (s *Set) New(path string, typ Type, value any, rights Rights) { s.Path = path s.Type = typ s.Value = value s.Rights = rights.GetRights() } // sets new driver typ with bus and address func (s *Set) NewDriverAddress(typ, bus string, address uint) { if s.Drivers == nil { s.Drivers = &Drivers{} } drv := s.Drivers.AddNewDriver(typ) b := drv.AddNewBus(bus) b.AddAddress(address) } // sets new driver typ with bus and subscription func (s *Set) NewDriverSubscribe(typ, bus string, sub string) { if s.Drivers == nil { s.Drivers = &Drivers{} } drv := s.Drivers.AddNewDriver(typ) b := drv.AddNewBus(bus) b.AddSubscription(sub) } // sets new driver typ with bus and publish func (s *Set) NewDriverPublish(typ, bus string, pub string) { if s.Drivers == nil { s.Drivers = &Drivers{} } drv := s.Drivers.AddNewDriver(typ) b := drv.AddNewBus(bus) b.AddPublish(pub) }