Add configuration file

This commit is contained in:
TwinProduction 2019-09-06 00:01:48 -04:00
parent b753443516
commit c1c46b6b30
5 changed files with 68 additions and 1 deletions

13
config.yaml Normal file
View File

@ -0,0 +1,13 @@
services:
- name: twinnation
url: https://twinnation.org/actuator/health
interval: 10
failure-threshold: 3
conditions:
- "$STATUS == 200"
- name: github
url: https://github.com
interval: 10
failure-threshold: 3
conditions:
- "$STATUS == 200"

45
config/config.go Normal file
View File

@ -0,0 +1,45 @@
package config
import (
"gopkg.in/yaml.v2"
"io/ioutil"
)
type Config struct {
Services []Service `yaml:"services"`
}
type Service struct {
Name string `yaml:"name"`
Url string `yaml:"url"`
Interval uint `yaml:"interval"`
FailureThreshold uint `yaml:"failure-threshold"`
Conditions []Condition `yaml:"conditions"`
}
type Condition string
var config *Config
func Get() *Config {
if config == nil {
ReadConfigurationFile("config.yaml")
}
return config
}
func ReadConfigurationFile(fileName string) *Config {
config = &Config{}
if bytes, err := ioutil.ReadFile(fileName); err == nil { // file exists
return ParseConfigBytes(bytes)
} else {
panic(err)
}
return config
}
func ParseConfigBytes(yamlBytes []byte) *Config {
config = &Config{}
yaml.Unmarshal(yamlBytes, config)
return config
}

5
go.mod
View File

@ -2,4 +2,7 @@ module github.com/TwinProduction/gatus
go 1.12
require k8s.io/helm v2.14.3+incompatible
require (
gopkg.in/yaml.v2 v2.2.2
k8s.io/helm v2.14.3+incompatible
)

3
go.sum
View File

@ -1,2 +1,5 @@
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
k8s.io/helm v2.14.3+incompatible h1:uzotTcZXa/b2SWVoUzM1xiCXVjI38TuxMujS/1s+3Gw=
k8s.io/helm v2.14.3+incompatible/go.mod h1:LZzlS4LQBHfciFOurYBFkCMTaZ0D1l+p0teMg7TSULI=

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"github.com/TwinProduction/gatus/config"
"github.com/TwinProduction/gatus/watchdog"
)
@ -11,4 +12,6 @@ func main() {
request.GetIp(result)
request.GetStatus(result)
fmt.Println(result)
fmt.Println(config.Get())
}