mirror of
https://github.com/TwiN/gatus.git
synced 2025-02-17 18:51:15 +01:00
Minor improvements
This commit is contained in:
parent
d1bb0cac16
commit
ffc50af67e
@ -15,24 +15,27 @@ var config *Config
|
|||||||
|
|
||||||
func Get() *Config {
|
func Get() *Config {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
ReadConfigurationFile("config.yaml")
|
cfg, err := readConfigurationFile("config.yaml")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
config = cfg
|
||||||
}
|
}
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadConfigurationFile(fileName string) *Config {
|
func readConfigurationFile(fileName string) (*Config, error) {
|
||||||
config = &Config{}
|
if bytes, err := ioutil.ReadFile(fileName); err == nil {
|
||||||
if bytes, err := ioutil.ReadFile(fileName); err == nil { // file exists
|
// file exists, so we'll parse it and return it
|
||||||
return ParseConfigBytes(bytes)
|
return parseConfigBytes(bytes), nil
|
||||||
} else {
|
} else {
|
||||||
panic(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
return config
|
return &Config{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseConfigBytes(yamlBytes []byte) *Config {
|
func parseConfigBytes(yamlBytes []byte) (config *Config) {
|
||||||
config = &Config{}
|
yaml.Unmarshal(yamlBytes, &config)
|
||||||
yaml.Unmarshal(yamlBytes, config)
|
|
||||||
for _, service := range config.Services {
|
for _, service := range config.Services {
|
||||||
if service.Interval == 0 {
|
if service.Interval == 0 {
|
||||||
service.Interval = 10 * time.Second
|
service.Interval = 10 * time.Second
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestParseConfigBytes(t *testing.T) {
|
func TestParseConfigBytes(t *testing.T) {
|
||||||
config := ParseConfigBytes([]byte(`
|
config := parseConfigBytes([]byte(`
|
||||||
services:
|
services:
|
||||||
- name: twinnation
|
- name: twinnation
|
||||||
url: https://twinnation.org/actuator/health
|
url: https://twinnation.org/actuator/health
|
||||||
@ -45,7 +45,7 @@ services:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseConfigBytesDefault(t *testing.T) {
|
func TestParseConfigBytesDefault(t *testing.T) {
|
||||||
config := ParseConfigBytes([]byte(`
|
config := parseConfigBytes([]byte(`
|
||||||
services:
|
services:
|
||||||
- name: twinnation
|
- name: twinnation
|
||||||
url: https://twinnation.org/actuator/health
|
url: https://twinnation.org/actuator/health
|
||||||
|
Loading…
Reference in New Issue
Block a user