-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
33 lines (27 loc) · 848 Bytes
/
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
package main
import (
"fmt"
"os"
"github.com/BurntSushi/toml"
)
// config is a struct that holds norav configuration
type config struct {
// Title of your norav dashboard
Title string `toml:"title"`
// Applications is a list of applications to be monitored
Applications []application `toml:"applications"`
// HealthCheckInterval is the interval in seconds to check the health of the applications
HealthCheckInterval int `toml:"interval"`
}
// loadConfigFile loads the configuration file if it exists
func loadConfigFile(f string) (config, error) {
if _, err := os.Stat(f); err != nil {
return config{}, fmt.Errorf("config file %s does not exist: %w", f, err)
}
var cfg config
_, err := toml.DecodeFile(f, &cfg)
if err != nil {
return config{}, fmt.Errorf("failed to decode config file %s: %w", f, err)
}
return cfg, nil
}