4 Commits

Author SHA1 Message Date
Adrian Zürcher
0f22443b93 add uuid to struct 2025-04-28 07:05:50 +02:00
Adrian Zürcher
0d3161337f change datatype 2025-04-27 16:09:38 +02:00
Adrian Zürcher
240f4fb3e7 add parse functons with io reader 2025-04-27 16:04:33 +02:00
Adrian Zürcher
bf36b023d3 add new repond function message 2025-04-27 09:51:32 +02:00
5 changed files with 49 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
package models
type Query struct {
Depth int `json:"depth,omitempty"`
Depth uint `json:"depth,omitempty"`
RegExp string `json:"regExp,omitempty"`
}

View File

@@ -19,6 +19,10 @@ func (r *Response) SendError(msg string) {
r.Message = msg
}
func (r *Response) SendMessage(msg string) {
r.Message = msg
}
func (r *Response) AddGet(get Get) {
get.Query = nil
r.Get = append(r.Get, get)
@@ -32,6 +36,13 @@ func (r *Response) AddSubscription(sub Subscribe) {
r.Subscribe = append(r.Subscribe, sub)
}
func (r *Response) AddUnsubscription(sub Subscribe) {
r.Subscribe = append(r.Subscribe, sub)
}
func (r *Response) AddUPublish(pub Publish) {
r.Publish = append(r.Publish, pub)
}
func (r *Response) IsValid() bool {
return !r.Error
}

View File

@@ -1,11 +1,14 @@
package models
import "github.com/google/uuid"
type Subscribe struct {
Path string `json:"path"`
Depth uint `json:"depth,omitempty"`
Drivers *Drivers `json:"drivers,omitempty"`
Driver string `json:"driver,omitempty"`
OnCreate bool `json:"onCreate,omitempty"`
OnDelete bool `json:"onDelete,omitempty"`
OnChange bool `json:"onChange,omitempty"`
Uuid uuid.UUID `json:"uuid,omitempty"`
Path string `json:"path,omitempty"`
Depth uint `json:"depth,omitempty"`
Drivers *Drivers `json:"drivers,omitempty"`
Driver string `json:"driver,omitempty"`
OnCreate bool `json:"onCreate,omitempty"`
OnDelete bool `json:"onDelete,omitempty"`
OnChange bool `json:"onChange,omitempty"`
}

View File

@@ -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
}

View File

@@ -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
}