abstract write to websocket and add request id

This commit is contained in:
Adrian Zürcher
2025-05-01 12:51:35 +02:00
parent 8e6b39c8bf
commit 4b36598bd7
4 changed files with 107 additions and 27 deletions

37
dbm/get.go Normal file
View File

@@ -0,0 +1,37 @@
package dbm
import (
json_data "github.com/tecamino/tecamino-json_data"
json_dataModels "github.com/tecamino/tecamino-json_data/models"
)
func (d *DBMHandler) Get(gets []json_dataModels.Get, id, id2 string) {
if gets == nil {
return
}
d.RLock()
defer d.RUnlock()
r := json_data.NewResponse()
r.Id = id2
for _, get := range gets {
var depth uint = 1
if get.Query != nil {
depth = get.Query.Depth
}
for _, dp := range d.DB.QueryDatapoints(depth, get.Path) {
r.AddGet(json_dataModels.Get{
Uuid: dp.Uuid,
Path: dp.Path,
Type: dp.Type,
Value: dp.Value,
Rights: dp.ReadWrite,
})
}
}
if err := d.Conns.SendResponse(id, r); err != nil {
d.Log.Error("get.Get", err.Error())
}
}