package main import ( "os" "github.com/BurntSushi/toml" ) type ServiceConfig struct { Enabled bool `toml:"enabled"` Subdomains []string `toml:"subdomains"` Directories []string `toml:"directories"` } type Config struct { Server struct { Listen string `toml:"listen"` } `toml:"server"` Services map[string]ServiceConfig `toml:"services"` Geo struct { AsnDB string `toml:"asn_db"` CityDB string `toml:"city_db"` DownloadURLAsn string `toml:"download_url_asn"` DownloadURLCity string `toml:"download_url_city"` CacheDir string `toml:"cache_dir"` } `toml:"geo"` } func LoadConfig(path string) (*Config, error) { var cfg Config f, err := os.Open(path) if err != nil { return nil, err } defer f.Close() if _, err := toml.NewDecoder(f).Decode(&cfg); err != nil { return nil, err } if cfg.Server.Listen == "" { cfg.Server.Listen = ":8080" } if cfg.Geo.CacheDir == "" { cfg.Geo.CacheDir = "data" } return &cfg, nil }