first commit
This commit is contained in:
commit
7181502a64
11 changed files with 770 additions and 0 deletions
50
config.go
Normal file
50
config.go
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue