Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
285a2add53 | ||
|
|
72d0d56868 | ||
|
|
ea4461fd7e | ||
|
|
0f22443b93 | ||
|
|
0d3161337f | ||
|
|
240f4fb3e7 |
@@ -1,10 +1,46 @@
|
||||
package models
|
||||
|
||||
import "github.com/google/uuid"
|
||||
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
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package models
|
||||
|
||||
type Query struct {
|
||||
Depth int `json:"depth,omitempty"`
|
||||
Depth uint `json:"depth,omitempty"`
|
||||
RegExp string `json:"regExp,omitempty"`
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package models
|
||||
|
||||
import "github.com/google/uuid"
|
||||
|
||||
type Subscribe struct {
|
||||
Path string `json:"path"`
|
||||
Uuid uuid.UUID `json:"uuid,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
Depth uint `json:"depth,omitempty"`
|
||||
Value any `json:"value,omitempty"`
|
||||
Drivers *Drivers `json:"drivers,omitempty"`
|
||||
Driver string `json:"driver,omitempty"`
|
||||
OnCreate bool `json:"onCreate,omitempty"`
|
||||
|
||||
21
request.go
21
request.go
@@ -1,7 +1,26 @@
|
||||
package tecaminodbmjson_data
|
||||
|
||||
import "github.com/tecamino/tecamino-json_data/models"
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
"github.com/tecamino/tecamino-json_data/models"
|
||||
)
|
||||
|
||||
func NewRequest() *models.Request {
|
||||
return &models.Request{}
|
||||
}
|
||||
|
||||
func ParseRequest(body io.ReadCloser) (*models.Request, error) {
|
||||
b, err := io.ReadAll(body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r := models.Request{}
|
||||
|
||||
err = json.Unmarshal(b, &r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package tecaminodbmjson_data
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
"github.com/tecamino/tecamino-json_data/models"
|
||||
)
|
||||
@@ -10,10 +11,14 @@ func NewResponse() *models.Response {
|
||||
return &models.Response{}
|
||||
}
|
||||
|
||||
func ParseResponse(b []byte) (*models.Response, error) {
|
||||
func ParseResponse(body io.ReadCloser) (*models.Response, error) {
|
||||
b, err := io.ReadAll(body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r := models.Response{}
|
||||
|
||||
err := json.Unmarshal(b, &r)
|
||||
err = json.Unmarshal(b, &r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user