Skip to content

Commit a7c130a

Browse files
committed
Added tags in template extraction
1 parent 30d5810 commit a7c130a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

internal/template/extract.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"encoding/json"
2222
"errors"
2323
"fmt"
24-
"io/ioutil"
2524
"os"
2625

2726
iotclient "github.com/arduino/iot-client-go/v2"
@@ -48,6 +47,16 @@ func FromThing(thing *iotclient.ArduinoThing) map[string]interface{} {
4847
}
4948
template["variables"] = props
5049

50+
if thing.Tags != nil {
51+
tags := []map[string]any{}
52+
for k, v := range thing.Tags {
53+
tag := make(map[string]any)
54+
tag[k] = v
55+
tags = append(tags, tag)
56+
}
57+
template["tags"] = tags
58+
}
59+
5160
return template
5261
}
5362

@@ -119,7 +128,7 @@ func ToFile(template map[string]interface{}, outfile string, format string) erro
119128
return errors.New("format is not valid: only 'json' and 'yaml' are supported")
120129
}
121130

122-
err = ioutil.WriteFile(outfile, file, os.FileMode(0644))
131+
err = os.WriteFile(outfile, file, os.FileMode(0644))
123132
if err != nil {
124133
return fmt.Errorf("%s: %w", "cannot write outfile: ", err)
125134
}

0 commit comments

Comments
 (0)