Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
ems-esp-logger
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jonas Leder
ems-esp-logger
Commits
ab943be6
Commit
ab943be6
authored
1 month ago
by
Jonas Leder
Browse files
Options
Downloads
Patches
Plain Diff
fix dhw values not stored in db
parent
7ebf5bf8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#54615
passed
1 month ago
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
helper/flattenJson.go
+21
-0
21 additions, 0 deletions
helper/flattenJson.go
main.go
+1
-1
1 addition, 1 deletion
main.go
messageworker/client.go
+3
-1
3 additions, 1 deletion
messageworker/client.go
with
25 additions
and
2 deletions
helper/flattenJson.go
0 → 100644
+
21
−
0
View file @
ab943be6
package
helper
func
FlattenJSON
(
prefix
string
,
input
map
[
string
]
interface
{},
output
map
[
string
]
interface
{})
{
for
key
,
value
:=
range
input
{
// Build the new key
newKey
:=
key
if
prefix
!=
""
{
newKey
=
prefix
+
"_"
+
key
}
// Check the type of value
switch
v
:=
value
.
(
type
)
{
case
map
[
string
]
interface
{}
:
// If it's a nested JSON object, recursively flatten it
FlattenJSON
(
newKey
,
v
,
output
)
default
:
// Otherwise, add it to the output map
output
[
newKey
]
=
v
}
}
}
This diff is collapsed.
Click to expand it.
main.go
+
1
−
1
View file @
ab943be6
...
...
@@ -18,7 +18,7 @@ func main() {
log
.
Init
()
queue
.
Init
()
if
os
.
Getenv
(
"OUTPUT_DATABSE"
)
!=
""
&&
os
.
Getenv
(
"CLIENT_USE_SERVER"
)
!=
"true"
{
if
(
os
.
Getenv
(
"OUTPUT_DATABSE"
)
!=
""
&&
os
.
Getenv
(
"CLIENT_USE_SERVER"
)
!=
"true"
)
||
os
.
Getenv
(
"LOGGER_SERVER"
)
==
"true"
{
database
.
Init
()
if
os
.
Getenv
(
"LOGGER_SERVER"
)
!=
"true"
{
database
.
CreateInstance
()
...
...
This diff is collapsed.
Click to expand it.
messageworker/client.go
+
3
−
1
View file @
ab943be6
...
...
@@ -98,6 +98,8 @@ func runDbClient() {
var
jsonData
map
[
string
]
interface
{}
err
=
json
.
Unmarshal
([]
byte
(
task
.
Data
),
&
jsonData
)
flattenedData
:=
make
(
map
[
string
]
interface
{})
helper
.
FlattenJSON
(
""
,
jsonData
,
flattenedData
)
if
err
!=
nil
{
log
.
Log
.
Error
(
"Failed decoding boiler JSON: "
,
err
.
Error
())
queue
.
MainQueue
.
Enqueue
(
taskData
,
60
)
...
...
@@ -105,7 +107,7 @@ func runDbClient() {
continue
}
valuesToInsert
:=
[]
tables
.
Value
{}
for
key
,
value
:=
range
json
Data
{
for
key
,
value
:=
range
flattened
Data
{
valueType
:=
database
.
GetOrCreateValueType
(
key
)
dbValue
:=
tables
.
Value
{
Date
:
task
.
Date
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment