-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
72 lines (63 loc) · 1.79 KB
/
config.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"encoding/json"
"errors"
"io"
"os"
"path/filepath"
)
type (
timeout struct {
MaxDuration int `json:"maxDuration"`
ProcessName *string `json:"processName"`
ProcessArguments *string `json:"processArguments"`
}
processData struct {
ProcessName *string `json:"processName"`
ProcessArguments *string `json:"processArguments"`
WorkingDirectory *string `json:"workingDirectory"`
EnvironmentVariables map[string]string `json:"environmentVariables"`
Timeout timeout `json:"timeout"`
Tags map[string]string `json:"tags"`
MetricsFilePath *string `json:"metricsFilePath"`
}
scenario struct {
processData
Name string `json:"name"`
}
config struct {
processData
FilePath string
Path string
FileName string
WarmUpCount int `json:"warmUpCount"`
Count int `json:"count"`
EnableDatadog bool `json:"enableDatadog"`
Scenarios []scenario `json:"scenarios"`
JsonExporterFilePath string `json:"jsonExporterFilePath"`
}
)
func loadConfiguration() (*config, error) {
if len(os.Args) < 2 {
return nil, errors.New("missing argument with the configuration file")
}
configurationFilePath := os.Args[1]
jsonFile, err := os.Open(configurationFilePath)
if err != nil {
return nil, err
}
defer jsonFile.Close()
jsonBytes, err2 := io.ReadAll(jsonFile)
if err2 != nil {
return nil, err2
}
var cfg config
err = json.Unmarshal(jsonBytes, &cfg)
if err != nil {
return nil, err
}
cfg.FilePath = configurationFilePath
cfg.Path = filepath.Dir(configurationFilePath)
cfg.FileName = filepath.Base(configurationFilePath)
return &cfg, nil
}