This commit is contained in:
Gregory Salaun 2024-07-01 23:24:53 +07:00
parent bf8a95bf21
commit 8d5d5ca34a

47
config.go Normal file
View File

@ -0,0 +1,47 @@
package main
import (
"fmt"
"os"
"gopkg.in/yaml.v2"
)
type Config struct {
Gotify struct {
URL string `yaml:"url"`
Token string `yanl:"token"`
} `yaml:"gotify"`
Cluster struct {
Host string `yaml:"host"`
Call string `yaml:"call"`
} `yaml:"cluster"`
}
func NewConfig(configPath string) (*Config, error) {
config := &Config{}
file, err := os.Open(configPath)
if err != nil {
return nil, err
}
defer file.Close()
d := yaml.NewDecoder(file)
if err := d.Decode(&config); err != nil {
return nil, err
}
return config, nil
}
func ValidateConfigPath(path string) error {
s, err := os.Stat(path)
if err != nil {
return err
}
if s.IsDir() {
return fmt.Errorf("'%s' is a directory, not a normal file", path)
}
return nil
}