update
This commit is contained in:
82
config.go
Normal file
82
config.go
Normal file
@ -0,0 +1,82 @@
|
||||
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"`
|
||||
HTTPServer bool `yaml:"httpserver"`
|
||||
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"`
|
||||
Command string `yanl:"command"`
|
||||
} `yaml:"cluster"`
|
||||
|
||||
Flex struct {
|
||||
IP string `yaml:"ip"`
|
||||
SpotLife string `yaml:"spot_life"`
|
||||
} `yaml:"flex"`
|
||||
|
||||
Clublog struct {
|
||||
Api string `yaml:"api"`
|
||||
} `yaml:"clublog"`
|
||||
|
||||
TelnetServer struct {
|
||||
Host string `yaml:"host"`
|
||||
Port string `yaml:"port"`
|
||||
} `yaml:"telnetserver"`
|
||||
|
||||
HTTPServer struct {
|
||||
Host string `yaml:"host"`
|
||||
Port string `yaml:"port"`
|
||||
} `yaml:"httpserver"`
|
||||
}
|
||||
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user