package main import ( "fmt" "os" "gopkg.in/yaml.v2" ) var ( Cfg *Config ) type Config struct { SQLite struct { SQLitePath string `yaml:"sqlite_path"` Callsign string `yaml:"callsign"` } `yaml:"sqlite"` Cluster struct { Server string `yaml:"server"` Port string `yaml:"port"` Login string `yaml:"login"` Skimmer bool `yaml:"skimmer"` FT8 bool `yaml:"ft8"` } `yaml:"cluster"` Flex struct { IP string `yaml:"ip"` SpotLife string `yaml:"spot_life"` } `yaml:"flex"` Clublog struct { Api string `yaml:"api"` } `yaml:"clublog"` Telnet struct { Host string `yaml:"host"` Port string `yaml:"port"` } `yaml:"telnet"` } func NewConfig(configPath string) error { config := &Config{} file, err := os.Open(configPath) if err != nil { return err } defer file.Close() d := yaml.NewDecoder(file) if err := d.Decode(&config); err != nil { return err } Cfg = config return 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 }