go-aws-dns/modules/setting.go

50 lines
702 B
Go
Raw Normal View History

package setting
import (
"io/ioutil"
"log"
"os"
"path"
"path/filepath"
"gopkg.in/yaml.v2"
)
type Config struct {
Domains []struct {
Name string `yaml:"name"`
Sub []string `yaml:"subdomain,flow"`
} `yaml:"domains"`
}
func LoadConfig(fp ...string) *Config {
var p string
if len(fp) > 0 && len(fp[0]) > 0 {
p = fp[0]
} else {
dir, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
p = path.Join(dir, "config.yml")
}
zone := &Config{}
p, err := filepath.Abs(p)
if err != nil {
log.Fatal(err)
}
data, err := ioutil.ReadFile(p)
if err != nil {
log.Fatal(err)
}
err = yaml.Unmarshal([]byte(data), &zone)
if err != nil {
log.Fatal(err)
}
return zone
}