This commit is contained in:
Jay
2019-05-08 18:01:06 +08:00
parent fe4bda3d57
commit f828db0a38
6 changed files with 72 additions and 3 deletions
+18
View File
@@ -2,10 +2,12 @@ package config
import (
"errors"
"io/ioutil"
"os"
"path"
"git.trj.tw/golang/utils"
"gopkg.in/yaml.v2"
)
// RecordData -
@@ -27,6 +29,8 @@ type Config struct {
Domains []DomainData `yaml:"domains"`
}
var conf *Config
// LoadConfig -
func LoadConfig(p ...string) error {
var fp string
@@ -42,9 +46,23 @@ func LoadConfig(p ...string) error {
fp = path.Join(wd, "config.yml")
}
fp = utils.ParsePath(fp)
if exists := utils.CheckExists(fp, false); !exists {
return errors.New("config file not exists")
}
data, err := ioutil.ReadFile(fp)
if err != nil {
return err
}
conf = &Config{}
err = yaml.Unmarshal(data, conf)
if err != nil {
return err
}
return nil
}
// GetConfig -
func GetConfig() *Config { return conf }