diff --git a/config.yaml b/config.yaml new file mode 100644 index 00000000..968deefd --- /dev/null +++ b/config.yaml @@ -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" \ No newline at end of file diff --git a/config/config.go b/config/config.go new file mode 100644 index 00000000..0d77a193 --- /dev/null +++ b/config/config.go @@ -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 +} diff --git a/go.mod b/go.mod index 9c43d44b..1f4fdda1 100644 --- a/go.mod +++ b/go.mod @@ -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 +) diff --git a/go.sum b/go.sum index b1f34353..7b886fab 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/main.go b/main.go index 16b7f9e9..65327194 100644 --- a/main.go +++ b/main.go @@ -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()) }