-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_exporter.go
45 lines (37 loc) · 948 Bytes
/
json_exporter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"encoding/json"
"fmt"
"math/rand"
"os"
"path/filepath"
)
type jsonExporter struct {
configuration *config
}
func newJsonExporter() Exporter {
return new(jsonExporter)
}
func (de *jsonExporter) SetConfiguration(configuration *config) {
de.configuration = configuration
}
func (de *jsonExporter) IsEnabled() bool {
return true
}
func (de *jsonExporter) Export(resScenario []scenarioResult) {
jsonData, err := json.MarshalIndent(resScenario, "", " ")
if err != nil {
fmt.Printf("Error exporting to json: %v\n", err)
return
}
outputFile := de.configuration.JsonExporterFilePath
if outputFile == "" {
outputFile = filepath.Join(de.configuration.Path, fmt.Sprintf("jsonexporter_%d.json", rand.Int()))
}
err = os.WriteFile(outputFile, jsonData, os.ModePerm)
if err != nil {
fmt.Printf("Error exporting to json: %v\n", err)
return
}
fmt.Printf("The Json file '%s' was exported.\n", outputFile)
}