add new convert function
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import "github.com/google/uuid"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/tecamino/tecamino-json_data/utils"
|
||||||
|
)
|
||||||
|
|
||||||
type Publish struct {
|
type Publish struct {
|
||||||
Event string `json:"event,omitempty"`
|
Event string `json:"event,omitempty"`
|
||||||
@@ -9,3 +14,33 @@ type Publish struct {
|
|||||||
Type Type `json:"type,omitempty"`
|
Type Type `json:"type,omitempty"`
|
||||||
Value any `json:"value,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
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user