42 lines
826 B
Go
42 lines
826 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"github.com/rs/zerolog/log"
|
||
|
"gopkg.in/yaml.v2"
|
||
|
"http-server-status/internal/pkg/checks"
|
||
|
"io/ioutil"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
var c Config
|
||
|
|
||
|
type Config struct {
|
||
|
HTTP struct{
|
||
|
Listen string `yaml:"listen"`
|
||
|
} `yaml:"http"`
|
||
|
Checks struct{
|
||
|
HDD checks.HDDConfig `yaml:"hdd"`
|
||
|
Load checks.LoadConfig `yaml:"load"`
|
||
|
Memory checks.MemmoryConfig `yaml:"memory"`
|
||
|
} `yaml:"checks"`
|
||
|
}
|
||
|
|
||
|
func readConfig() {
|
||
|
fmt.Println(os.Args)
|
||
|
filename := "/etc/http-server-status/config.yml"
|
||
|
if len(os.Args) > 1 {
|
||
|
filename = os.Args[1]
|
||
|
}
|
||
|
|
||
|
log.Debug().Str("filename", filename).Msg("Load Config")
|
||
|
yamlFile, err := ioutil.ReadFile(filename)
|
||
|
if err != nil {
|
||
|
log.Fatal().Err(err).Msg("Cant get config file")
|
||
|
}
|
||
|
|
||
|
err = yaml.Unmarshal(yamlFile, &c)
|
||
|
if err != nil {
|
||
|
log.Fatal().Err(err).Msg("Cant parse yaml file")
|
||
|
}
|
||
|
}
|