50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package models
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/tecamino/tecamino-json_data/utils"
|
|
)
|
|
|
|
// publish model
|
|
type Publish struct {
|
|
Event string `json:"event,omitempty"` // publish event onCreate|onChange|onDelete
|
|
Uuid uuid.UUID `json:"uuid,omitempty"` // universally unique identifier
|
|
Drivers *Drivers `json:"drivers,omitempty"` // assigned drivers
|
|
Path string `json:"path,omitempty"` // dbm path
|
|
Type Type `json:"type,omitempty"` // dbm datatype
|
|
Value any `json:"value,omitempty"` // dbm value
|
|
}
|
|
|
|
// returns input parameter as assigned dbm datatype
|
|
func (p *Publish) ConvertValue() any {
|
|
switch p.Type {
|
|
case BIT:
|
|
return utils.BoolFrom(p.Value)
|
|
case BYS:
|
|
return utils.Int8From(p.Value)
|
|
case BYU:
|
|
return utils.Uint8From(p.Value)
|
|
case WOS:
|
|
return utils.Int16From(p.Value)
|
|
case WOU:
|
|
return utils.Uint16From(p.Value)
|
|
case DWS:
|
|
return utils.Int32From(p.Value)
|
|
case DWU:
|
|
return utils.Uint32From(p.Value)
|
|
case LOS:
|
|
return utils.Int64From(p.Value)
|
|
case LOU:
|
|
return utils.Uint64From(p.Value)
|
|
case F32:
|
|
return utils.Float32From(p.Value)
|
|
case F64:
|
|
return utils.Float64From(p.Value)
|
|
case STR:
|
|
return fmt.Sprintf("%v", p.Value)
|
|
}
|
|
return nil
|
|
}
|