Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72d0d56868 | ||
|
|
ea4461fd7e | ||
|
|
0f22443b93 | ||
|
|
0d3161337f | ||
|
|
240f4fb3e7 | ||
|
|
bf36b023d3 | ||
|
|
a8127cc381 | ||
|
|
8615d8c3d5 | ||
|
|
6c327cf284 | ||
|
|
40648c5fd8 | ||
|
|
1b035e710f | ||
|
|
93f2188cc8 | ||
|
|
862d865338 |
@@ -1,2 +1,2 @@
|
||||
# tecamino-dbm-models
|
||||
# tecamino-json data models
|
||||
Database Manager Models
|
||||
|
||||
2
go.mod
2
go.mod
@@ -1,4 +1,4 @@
|
||||
module github.com/tecamino/tecamino-dbm-json_data
|
||||
module github.com/tecamino/tecamino-json_data
|
||||
|
||||
go 1.21.0
|
||||
|
||||
|
||||
@@ -6,5 +6,6 @@ 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"`
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package models
|
||||
|
||||
type Query struct {
|
||||
Depth int `json:"depth,omitempty"`
|
||||
Depth uint `json:"depth,omitempty"`
|
||||
RegExp string `json:"regExp,omitempty"`
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -3,7 +3,7 @@ package models
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/tecamino/tecamino-dbm-json_data/utils"
|
||||
"github.com/tecamino/tecamino-json_data/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
21
request.go
21
request.go
@@ -1,7 +1,26 @@
|
||||
package tecaminodbmjson_data
|
||||
|
||||
import "github.com/tecamino/tecamino-dbm-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
|
||||
}
|
||||
|
||||
15
response.go
15
response.go
@@ -2,14 +2,23 @@ package tecaminodbmjson_data
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
"github.com/tecamino/tecamino-dbm-json_data/models"
|
||||
"github.com/tecamino/tecamino-json_data/models"
|
||||
)
|
||||
|
||||
func ParseResponse(b []byte) (*models.Response, error) {
|
||||
func NewResponse() *models.Response {
|
||||
return &models.Response{}
|
||||
}
|
||||
|
||||
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