52 lines
831 B
Go
52 lines
831 B
Go
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"`
|
|
|
|
Log struct {
|
|
SQLitePath string `yaml:"sqlitePath"`
|
|
} `yaml:"log"`
|
|
}
|
|
|
|
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
|
|
}
|