46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
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
|
|
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) NewDriver(typ, bus string, address uint) {
|
|
s.Driver = &Driver{
|
|
Type: typ,
|
|
Bus: bus,
|
|
Address: address,
|
|
}
|
|
}
|