implement new json_data model
This commit is contained in:
@@ -1,79 +1,186 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zuadi/tecamino-dbm/utils"
|
||||
"github.com/coder/websocket/wsjson"
|
||||
"github.com/google/uuid"
|
||||
serverModels "github.com/tecamino/tecamino-dbm/server/models"
|
||||
"github.com/tecamino/tecamino-dbm/utils"
|
||||
json_data "github.com/tecamino/tecamino-json_data"
|
||||
json_dataModels "github.com/tecamino/tecamino-json_data/models"
|
||||
)
|
||||
|
||||
const (
|
||||
OnCreate = "onCreate"
|
||||
OnChange = "onChange"
|
||||
OnDelete = "onDelete"
|
||||
)
|
||||
|
||||
type Datapoint struct {
|
||||
Datapoints map[string]*Datapoint `json:"-"`
|
||||
Path string `json:"path"`
|
||||
Value any `json:"value,omitempty"`
|
||||
CreateDateTime int64 `json:"createDateTime,omitempty"`
|
||||
UpdateDateTime int64 `json:"updateDateTime,omitempty"`
|
||||
Type Type `json:"type"`
|
||||
ReadWrite Rights `json:"readWrite"`
|
||||
Drivers map[string]*Driver `json:"-"`
|
||||
Subscribtions Subscribtions `json:"-"`
|
||||
Datapoints map[string]*Datapoint `json:"-"`
|
||||
Uuid uuid.UUID `json:"uuid"`
|
||||
Path string `json:"path"`
|
||||
Value any `json:"value,omitempty"`
|
||||
CreateDateTime int64 `json:"createDateTime,omitempty"`
|
||||
UpdateDateTime int64 `json:"updateDateTime,omitempty"`
|
||||
Type json_dataModels.Type `json:"type"`
|
||||
ReadWrite json_dataModels.Rights `json:"readWrite"`
|
||||
Drivers json_dataModels.Drivers `json:"drivers,omitempty"`
|
||||
Subscriptions Subscriptions `json:"-"`
|
||||
}
|
||||
|
||||
func (d *Datapoint) CreateDatapoint(typ Type, value any, rights Rights, path string) error {
|
||||
parts := regexp.MustCompile(`[:]+`).Split(path, -1)
|
||||
func (d *Datapoint) Set(path string, set json_dataModels.Set) (bool, error) {
|
||||
var changed bool
|
||||
if path != "" {
|
||||
changed = true
|
||||
d.Path = path
|
||||
}
|
||||
|
||||
current := d
|
||||
for i, part := range parts {
|
||||
if current.Datapoints == nil {
|
||||
current.Datapoints = make(map[string]*Datapoint)
|
||||
if set.Type != "" {
|
||||
changed = true
|
||||
d.Type = set.Type
|
||||
}
|
||||
|
||||
if d.Type != "" {
|
||||
if d.Value == nil && set.Value == nil {
|
||||
changed = true
|
||||
d.Value = d.Type.DefaultValue()
|
||||
} else if d.Value != d.Type.ConvertValue(set.Value) {
|
||||
changed = true
|
||||
d.Value = d.Type.ConvertValue(set.Value)
|
||||
}
|
||||
|
||||
if i == len(parts)-1 {
|
||||
// Leaf node: create or update datapoint
|
||||
if existing, ok := current.Datapoints[part]; ok {
|
||||
// Update existing
|
||||
existing.Type = typ
|
||||
existing.ReadWrite = rights.GetRights()
|
||||
existing.Value = typ.ConvertValue(value)
|
||||
existing.UpdateDateTime = time.Now().UnixMilli()
|
||||
} else {
|
||||
// Create new
|
||||
current.Datapoints[part] = &Datapoint{
|
||||
Path: strings.Join(parts, ":"),
|
||||
Type: typ,
|
||||
Value: typ.ConvertValue(value),
|
||||
ReadWrite: rights.GetRights(),
|
||||
CreateDateTime: time.Now().UnixMilli(),
|
||||
UpdateDateTime: time.Now().UnixMilli(),
|
||||
Subscribtions: InitSubscribtion(),
|
||||
}
|
||||
if set.Rights != "" {
|
||||
changed = true
|
||||
d.ReadWrite = set.Rights.GetRights()
|
||||
}
|
||||
|
||||
if changed {
|
||||
d.UpdateDateTime = time.Now().UnixMilli()
|
||||
}
|
||||
|
||||
if set.Driver == nil {
|
||||
return changed, nil
|
||||
}
|
||||
if set.Driver.Type == "" {
|
||||
return changed, errors.New("driver type missing")
|
||||
}
|
||||
if set.Driver.Bus == "" {
|
||||
return changed, errors.New("driver bus name missing")
|
||||
}
|
||||
|
||||
if d.Drivers == nil {
|
||||
d.Drivers = json_dataModels.NewDrivers()
|
||||
}
|
||||
d.Drivers.AddDriver(set.Driver.Type, set.Driver.Bus, set.Driver.Address)
|
||||
d.UpdateDateTime = time.Now().UnixMilli()
|
||||
|
||||
return changed, nil
|
||||
}
|
||||
|
||||
func (d *Datapoint) GetValueUint64() uint64 {
|
||||
return utils.Uint64From(d.Value)
|
||||
}
|
||||
|
||||
func (d *Datapoint) CreateDatapoints(conns *serverModels.Connections, sets ...json_dataModels.Set) (created []json_dataModels.Set, err error) {
|
||||
if len(sets) == 0 {
|
||||
return
|
||||
}
|
||||
for _, dp := range sets {
|
||||
parts := strings.Split(dp.Path, ":")
|
||||
|
||||
current := d
|
||||
for i, part := range parts {
|
||||
if current.Datapoints == nil {
|
||||
current.Datapoints = make(map[string]*Datapoint)
|
||||
}
|
||||
|
||||
if i == len(parts)-1 {
|
||||
// Leaf node: create or update datapoint
|
||||
if existing, ok := current.Datapoints[part]; ok {
|
||||
publish, err := existing.Set("", dp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
created = append(created, json_dataModels.Set{
|
||||
Uuid: existing.Uuid,
|
||||
Path: existing.Path,
|
||||
Type: existing.Type,
|
||||
Value: existing.Value,
|
||||
Rights: existing.ReadWrite,
|
||||
Drivers: &existing.Drivers,
|
||||
Updated: true,
|
||||
})
|
||||
|
||||
if publish {
|
||||
existing.Publish(conns, OnChange)
|
||||
}
|
||||
} else {
|
||||
// Create new
|
||||
current.Datapoints[part] = &Datapoint{
|
||||
Uuid: uuid.New(),
|
||||
CreateDateTime: time.Now().UnixMilli(),
|
||||
Subscriptions: InitSubscribtion(),
|
||||
}
|
||||
publish, err := current.Datapoints[part].Set(strings.Join(parts, ":"), dp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
created = append(created, json_dataModels.Set{
|
||||
Uuid: current.Uuid,
|
||||
Path: current.Path,
|
||||
Type: current.Type,
|
||||
Value: current.Value,
|
||||
Rights: current.ReadWrite,
|
||||
Driver: dp.Driver,
|
||||
})
|
||||
if publish {
|
||||
current.Publish(conns, OnChange)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Traverse or create intermediate datapoints
|
||||
if next, ok := current.Datapoints[part]; ok {
|
||||
current = next
|
||||
} else {
|
||||
newDp := &Datapoint{
|
||||
Path: strings.Join(parts[:i+1], ":"),
|
||||
Type: NONE,
|
||||
ReadWrite: rights.GetRights(),
|
||||
CreateDateTime: time.Now().UnixMilli(),
|
||||
UpdateDateTime: time.Now().UnixMilli(),
|
||||
Subscribtions: InitSubscribtion(),
|
||||
// Traverse or create intermediate datapoints
|
||||
if next, ok := current.Datapoints[part]; ok {
|
||||
current = next
|
||||
} else {
|
||||
newDp := &Datapoint{
|
||||
Uuid: uuid.New(),
|
||||
Path: strings.Join(parts[:i+1], ":"),
|
||||
Type: json_dataModels.NONE,
|
||||
CreateDateTime: time.Now().UnixMilli(),
|
||||
UpdateDateTime: time.Now().UnixMilli(),
|
||||
Subscriptions: InitSubscribtion(),
|
||||
}
|
||||
|
||||
created = append(created, json_dataModels.Set{
|
||||
Uuid: newDp.Uuid,
|
||||
Path: newDp.Path,
|
||||
Type: newDp.Type,
|
||||
Value: newDp.Value,
|
||||
Rights: newDp.ReadWrite,
|
||||
})
|
||||
|
||||
if dp.Rights != "" {
|
||||
newDp.ReadWrite = dp.Rights.GetRights()
|
||||
}
|
||||
|
||||
current.Datapoints[part] = newDp
|
||||
current = newDp
|
||||
}
|
||||
current.Datapoints[part] = newDp
|
||||
current = newDp
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Datapoint) ImportDatapoint(dp *Datapoint, path string) error {
|
||||
parts := regexp.MustCompile(`[:]+`).Split(path, -1)
|
||||
func (d *Datapoint) ImportDatapoint(conns *serverModels.Connections, dp Datapoint, path string) error {
|
||||
parts := strings.Split(dp.Path, ":")
|
||||
|
||||
current := d
|
||||
for i, part := range parts {
|
||||
@@ -88,12 +195,14 @@ func (d *Datapoint) ImportDatapoint(dp *Datapoint, path string) error {
|
||||
existing.Value = current.Type.ConvertValue(dp.Value)
|
||||
existing.ReadWrite = dp.ReadWrite.GetRights()
|
||||
existing.UpdateDateTime = time.Now().UnixMilli()
|
||||
dp.Publish(conns, OnChange)
|
||||
} else {
|
||||
dp.Path = strings.Join(parts, ":")
|
||||
dp.ReadWrite = dp.ReadWrite.GetRights()
|
||||
dp.UpdateDateTime = time.Now().UnixMilli()
|
||||
dp.Subscribtions = InitSubscribtion()
|
||||
current.Datapoints[part] = dp
|
||||
dp.Subscriptions = InitSubscribtion()
|
||||
current.Datapoints[part] = &dp
|
||||
dp.Publish(conns, OnChange)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -104,7 +213,7 @@ func (d *Datapoint) ImportDatapoint(dp *Datapoint, path string) error {
|
||||
} else {
|
||||
newDp := &Datapoint{
|
||||
Path: strings.Join(parts[:i+1], ":"),
|
||||
Type: NONE,
|
||||
Type: json_dataModels.NONE,
|
||||
ReadWrite: dp.ReadWrite.GetRights(),
|
||||
UpdateDateTime: time.Now().UnixMilli(),
|
||||
}
|
||||
@@ -116,9 +225,9 @@ func (d *Datapoint) ImportDatapoint(dp *Datapoint, path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Datapoint) UpdateDatapointValue(value any, path string) error {
|
||||
func (d *Datapoint) UpdateDatapointValue(conns *serverModels.Connections, value any, path string) error {
|
||||
|
||||
paths := regexp.MustCompile(`[:]+`).Split(path, -1)
|
||||
paths := strings.Split(path, ":")
|
||||
|
||||
current := d
|
||||
for i, part := range paths {
|
||||
@@ -129,6 +238,7 @@ func (d *Datapoint) UpdateDatapointValue(value any, path string) error {
|
||||
if i == len(paths)-1 {
|
||||
dp.Value = dp.Type.ConvertValue(value)
|
||||
dp.UpdateDateTime = time.Now().UnixMilli()
|
||||
dp.Publish(conns, OnChange)
|
||||
return nil
|
||||
}
|
||||
current = dp
|
||||
@@ -136,40 +246,38 @@ func (d *Datapoint) UpdateDatapointValue(value any, path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Datapoint) RemoveDatapoint(path string) error {
|
||||
parts := regexp.MustCompile(`[:]+`).Split(path, -1)
|
||||
func (d *Datapoint) RemoveDatapoint(conns *serverModels.Connections, set json_dataModels.Set) (json_dataModels.Set, error) {
|
||||
parts := strings.Split(set.Path, ":")
|
||||
|
||||
if len(parts) < 1 {
|
||||
return fmt.Errorf("invalid path: '%s'", path)
|
||||
return json_dataModels.Set{}, fmt.Errorf("invalid path: '%s'", set.Path)
|
||||
}
|
||||
|
||||
current := d
|
||||
for i := range len(parts) - 1 {
|
||||
next, ok := current.Datapoints[parts[i]]
|
||||
if !ok {
|
||||
return fmt.Errorf("path not found: '%s'", strings.Join(parts[:i+1], ":"))
|
||||
return json_dataModels.Set{}, fmt.Errorf("path not found: '%s'", strings.Join(parts[:i+1], ":"))
|
||||
}
|
||||
current = next
|
||||
}
|
||||
|
||||
toDelete := parts[len(parts)-1]
|
||||
if _, ok := current.Datapoints[toDelete]; ok {
|
||||
if dp, ok := current.Datapoints[toDelete]; ok {
|
||||
dp.Publish(conns, OnDelete)
|
||||
delete(current.Datapoints, toDelete)
|
||||
fmt.Println("Removed datapoint:", path)
|
||||
return nil
|
||||
return json_dataModels.Set{
|
||||
Uuid: set.Uuid,
|
||||
Path: set.Path,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("datapoint '%s' not found", path)
|
||||
return json_dataModels.Set{}, fmt.Errorf("datapoint '%s' not found", set.Path)
|
||||
}
|
||||
|
||||
func (d *Datapoint) GetAllDatapoints(depth int) (dps []*Datapoint) {
|
||||
|
||||
var dfs func(dp *Datapoint, currentDepth int)
|
||||
dfs = func(dp *Datapoint, currentDepth int) {
|
||||
if currentDepth == 0 {
|
||||
dps = append(dps, dp)
|
||||
}
|
||||
func (d *Datapoint) GetAllDatapoints(depth uint) (dps []*Datapoint) {
|
||||
|
||||
var dfs func(dp *Datapoint, currentDepth uint)
|
||||
dfs = func(dp *Datapoint, currentDepth uint) {
|
||||
if depth == 1 {
|
||||
return
|
||||
} else if depth == 0 {
|
||||
@@ -186,15 +294,16 @@ func (d *Datapoint) GetAllDatapoints(depth int) (dps []*Datapoint) {
|
||||
}
|
||||
|
||||
for _, child := range dp.Datapoints {
|
||||
dps = append(dps, child)
|
||||
dfs(child, currentDepth+1)
|
||||
}
|
||||
}
|
||||
|
||||
dps = append(dps, d)
|
||||
dfs(d, 0)
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Datapoint) QueryDatapoints(depth int, path string) (dps []*Datapoint) {
|
||||
func (d *Datapoint) QueryDatapoints(depth uint, path string) (dps []*Datapoint) {
|
||||
parts := strings.Split(path, ":")
|
||||
|
||||
var dfs func(current *Datapoint, index int)
|
||||
@@ -222,17 +331,17 @@ func (d *Datapoint) QueryDatapoints(depth int, path string) (dps []*Datapoint) {
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Datapoint) AddSubscribtion(id string, sub *Subscribe) {
|
||||
if d.Subscribtions == nil {
|
||||
func (d *Datapoint) AddSubscribtion(id string, sub json_dataModels.Subscribe) {
|
||||
if d.Subscriptions == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if s, ok := d.Subscribtions[id]; ok {
|
||||
if s, ok := d.Subscriptions[id]; ok {
|
||||
s.OnCreate = sub.OnCreate
|
||||
s.OnChange = sub.OnChange
|
||||
s.OnDelete = sub.OnDelete
|
||||
} else {
|
||||
d.Subscribtions[id] = &Subscribtion{
|
||||
d.Subscriptions[id] = &Subscription{
|
||||
OnCreate: sub.OnCreate,
|
||||
OnChange: sub.OnChange,
|
||||
OnDelete: sub.OnDelete,
|
||||
@@ -241,37 +350,35 @@ func (d *Datapoint) AddSubscribtion(id string, sub *Subscribe) {
|
||||
}
|
||||
|
||||
func (d *Datapoint) RemoveSubscribtion(id string) {
|
||||
if _, ok := d.Subscribtions[id]; !ok {
|
||||
if _, ok := d.Subscriptions[id]; !ok {
|
||||
return
|
||||
}
|
||||
delete(d.Subscribtions, id)
|
||||
delete(d.Subscriptions, id)
|
||||
}
|
||||
|
||||
func (d *Datapoint) AddDriver(driver, bus string, adr int) {
|
||||
if d.Drivers == nil {
|
||||
d.Drivers = make(map[string]*Driver)
|
||||
func (d *Datapoint) Publish(conns *serverModels.Connections, eventType string) error {
|
||||
if conns.Clients == nil {
|
||||
return nil
|
||||
}
|
||||
conns.RLock()
|
||||
defer conns.RUnlock()
|
||||
|
||||
d.Drivers[driver] = &Driver{
|
||||
Bus: bus,
|
||||
Address: adr,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Datapoint) AddDriverSubscribtion(id string, sub *Subscribe) {
|
||||
if s, ok := d.Subscribtions[id]; ok {
|
||||
s.OnCreate = sub.OnCreate
|
||||
s.OnChange = sub.OnChange
|
||||
s.OnDelete = sub.OnDelete
|
||||
} else {
|
||||
d.Subscribtions[id] = &Subscribtion{
|
||||
OnCreate: sub.OnCreate,
|
||||
OnChange: sub.OnChange,
|
||||
OnDelete: sub.OnDelete,
|
||||
for id := range d.Subscriptions {
|
||||
if client, ok := conns.Clients[id]; !ok {
|
||||
delete(d.Subscriptions, id)
|
||||
} else {
|
||||
r := json_data.NewResponse()
|
||||
r.AddUPublish(json_dataModels.Publish{
|
||||
Event: eventType,
|
||||
Uuid: d.Uuid,
|
||||
Path: d.Path,
|
||||
Value: d.Value,
|
||||
})
|
||||
err := wsjson.Write(client.Ctx, client.Conn, r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Datapoint) GetValueUint64() uint64 {
|
||||
return utils.Uint64From(d.Value)
|
||||
return nil
|
||||
}
|
||||
|
@@ -1,6 +0,0 @@
|
||||
package models
|
||||
|
||||
type Driver struct {
|
||||
Bus string
|
||||
Address int
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
package models
|
||||
|
||||
type Get struct {
|
||||
Path string `json:"path"`
|
||||
Query *Query `json:"query,omitempty"`
|
||||
}
|
@@ -1,35 +0,0 @@
|
||||
package models
|
||||
|
||||
type JsonData struct {
|
||||
Get *[]Get `json:"get,omitempty"`
|
||||
Set *[]Set `json:"set,omitempty"`
|
||||
Subscribe *[]Subscribe `json:"subscribe,omitempty"`
|
||||
Unsubscribe *[]Subscribe `json:"unsubscribe,omitempty"`
|
||||
}
|
||||
|
||||
func NewRequest() *JsonData {
|
||||
return &JsonData{}
|
||||
|
||||
}
|
||||
|
||||
func (r *JsonData) AddGet(path string, query Query) {
|
||||
if r.Get == nil {
|
||||
r.Get = &[]Get{}
|
||||
}
|
||||
|
||||
*r.Get = append(*r.Get, Get{
|
||||
Path: path,
|
||||
Query: &query,
|
||||
})
|
||||
}
|
||||
|
||||
func (r *JsonData) AddSet(path string, value any, create bool) {
|
||||
if r.Set == nil {
|
||||
r.Set = &[]Set{}
|
||||
}
|
||||
|
||||
*r.Set = append(*r.Set, Set{
|
||||
Path: path,
|
||||
Value: value,
|
||||
})
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
package models
|
||||
|
||||
type JsonResponse struct {
|
||||
Error *bool `json:"error,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Data string `json:"data,omitempty"`
|
||||
Event string `json:"event,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
Value any `json:"value,omitempty"`
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
package models
|
||||
|
||||
type Query struct {
|
||||
Depth int `json:"depth,omitempty"`
|
||||
RegExp string `json:"regExp,omitempty"`
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
package models
|
||||
|
||||
type Rights string
|
||||
|
||||
const (
|
||||
Read Rights = "R"
|
||||
Write Rights = "W"
|
||||
ReadWrite Rights = "RW"
|
||||
)
|
||||
|
||||
func (r *Rights) GetRights() Rights {
|
||||
if r == nil {
|
||||
return ReadWrite
|
||||
} else if *r == "" {
|
||||
return ReadWrite
|
||||
}
|
||||
return *r
|
||||
}
|
@@ -1,8 +0,0 @@
|
||||
package models
|
||||
|
||||
type Set struct {
|
||||
Path string `json:"path"`
|
||||
Driver *Driver `json:"driver,omitempty"`
|
||||
Value any `json:"value,omitempty"`
|
||||
Create bool `json:"create,omitempty"`
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
package models
|
||||
|
||||
type Subscribe struct {
|
||||
Path string `json:"path"`
|
||||
Depth int `json:"depth"`
|
||||
Driver *string `json:"driver,omitempty"`
|
||||
OnCreate bool `json:"onCreate"`
|
||||
OnDelete bool `json:"onDelete"`
|
||||
OnChange bool `json:"onChange"`
|
||||
}
|
@@ -1,13 +1,13 @@
|
||||
package models
|
||||
|
||||
type Subscribtions map[string]*Subscribtion
|
||||
type Subscriptions map[string]*Subscription
|
||||
|
||||
type Subscribtion struct {
|
||||
type Subscription struct {
|
||||
OnCreate bool
|
||||
OnDelete bool
|
||||
OnChange bool
|
||||
}
|
||||
|
||||
func InitSubscribtion() Subscribtions {
|
||||
return make(Subscribtions)
|
||||
func InitSubscribtion() Subscriptions {
|
||||
return make(Subscriptions)
|
||||
}
|
||||
|
@@ -1,67 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/zuadi/tecamino-dbm/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
NONE Type = "NONE"
|
||||
BIT Type = "BIT"
|
||||
BYU Type = "BYU" // UINT8
|
||||
BYS Type = "BYS" // INT8
|
||||
WOS Type = "WOS" // INT16
|
||||
WOU Type = "WOU" // UINT16
|
||||
DWS Type = "DWS" // INT32
|
||||
DWU Type = "DWU" // UINT32
|
||||
LOS Type = "LOS" // INT64
|
||||
LOU Type = "LOU" // UINT64
|
||||
F32 Type = "F32" // FLOAT32
|
||||
F64 Type = "F64" // FLOAT64
|
||||
STR Type = "STRING" // STRING
|
||||
)
|
||||
|
||||
type Type string
|
||||
|
||||
func (t *Type) DefaultValue(v any) any {
|
||||
switch *t {
|
||||
case BIT:
|
||||
return false
|
||||
case BYS, BYU, WOS, WOU, DWS, DWU, LOS, LOU, F32, F64:
|
||||
return 0
|
||||
case STR:
|
||||
return ""
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Type) ConvertValue(v any) any {
|
||||
switch *t {
|
||||
case BIT:
|
||||
return utils.BoolFrom(v)
|
||||
case BYS:
|
||||
return utils.Int8From(v)
|
||||
case BYU:
|
||||
return utils.Uint8From(v)
|
||||
case WOS:
|
||||
return utils.Int16From(v)
|
||||
case WOU:
|
||||
return utils.Uint16From(v)
|
||||
case DWS:
|
||||
return utils.Int32From(v)
|
||||
case DWU:
|
||||
return utils.Uint32From(v)
|
||||
case LOS:
|
||||
return utils.Int64From(v)
|
||||
case LOU:
|
||||
return utils.Uint64From(v)
|
||||
case F32:
|
||||
return utils.Float32From(v)
|
||||
case F64:
|
||||
return utils.Float64From(v)
|
||||
case STR:
|
||||
return fmt.Sprintf("%v", v)
|
||||
}
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user