Skip to content

Commit 8d54a10

Browse files
bluecmdsecustor
authored andcommitted
refactor(config): Internal store as pointer
This ensures that you can call config.Init() in tests that otherwise have already called flag.Parse().
1 parent f28587e commit 8d54a10

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Diff for: internal/config/main.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,20 @@ var (
5151
TlsExtraCAs: flag.String("extra-ca-certs", "", "comma-separated files containing extra PEMs to trust for TLS connections in addition to the system trust store"),
5252
}
5353

54-
savedConfig FortiExporterConfig
54+
savedConfig *FortiExporterConfig
5555
)
5656

5757
func Init() error {
5858
// check if already parsed
59-
if flag.Parsed() {
59+
if savedConfig != nil {
6060
return nil
6161
}
6262

63-
flag.Parse()
63+
if !flag.Parsed() {
64+
flag.Parse()
65+
}
6466

65-
savedConfig = FortiExporterConfig{
67+
savedConfig = &FortiExporterConfig{
6668
Listen: *parameter.Listen,
6769
ScrapeTimeout: *parameter.ScrapeTimeout,
6870
TLSTimeout: *parameter.TLSTimeout,
@@ -106,5 +108,5 @@ func Init() error {
106108
}
107109

108110
func GetConfig() FortiExporterConfig {
109-
return savedConfig
111+
return *savedConfig
110112
}

0 commit comments

Comments
 (0)