Files
tecamino-json_data/models/publish.go
2025-04-29 08:21:40 +02:00

47 lines
962 B
Go

package models
import (
"fmt"
"github.com/google/uuid"
"github.com/tecamino/tecamino-json_data/utils"
)
type Publish struct {
Event string `json:"event,omitempty"`
Uuid uuid.UUID `json:"uuid,omitempty"`
Path string `json:"path,omitempty"`
Type Type `json:"type,omitempty"`
Value any `json:"value,omitempty"`
}
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
}