FlexDXCluster/config.go
2024-11-16 12:24:42 +07:00

76 lines
1.6 KiB
Go

package main
import (
"fmt"
"log"
"os"
"gopkg.in/yaml.v2"
)
var Cfg *Config
type Config struct {
General struct {
DeleteLogFileAtStart bool `yaml:"delete_log_file_at_start"`
LogToFile bool `yaml:"log_to_file"`
LogLevel string `yaml:"log_level"`
TelnetServer bool `yaml:"telnetserver"`
FlexRadioSpot bool `yaml:"flexradiospot"`
} `yaml:"general"`
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"`
FT4 bool `yaml:"ft4"`
Command string `yanl:"command"`
LoginPrompt string `yaml:"login_prompt"`
} `yaml:"cluster"`
Flex struct {
Discover bool `yaml:"discovery"`
IP string `yaml:"ip"`
SpotLife string `yaml:"spot_life"`
} `yaml:"flex"`
TelnetServer struct {
Host string `yaml:"host"`
Port string `yaml:"port"`
} `yaml:"telnetserver"`
}
func NewConfig(configPath string) *Config {
Cfg = &Config{}
file, err := os.Open(configPath)
if err != nil {
log.Println("could not open config file")
}
defer file.Close()
d := yaml.NewDecoder(file)
if err := d.Decode(&Cfg); err != nil {
log.Println("could not decod config file")
}
return Cfg
}
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
}