package conf import ( "gopkg.in/yaml.v2" "os" ) type EnvConfig struct { DbType string `yaml:"dbtype"` Server string `yaml:"server"` Ip string `yaml:"ip"` User string `yaml:"user"` Password string `yaml:"password"` DbName string `yaml:"dbname"` Port int `yaml:"port"` TemplatePath string `yaml:"templatepath"` ReadTaskInterval int `yaml:"readtaskinterval"` PrinterType string `yaml:"printertype"` Finr int `yaml:"finr"` Inbox string `yaml:"inbox"` Outbox string `yaml:"outbox"` Log string `yaml:"log"` } //read yaml config //注:path为yaml或yml文件的路径 func ReadYamlConfig(path string) (*EnvConfig,error){ conf := &EnvConfig{} f, err := os.Open(path) if err != nil { return nil,err } else { yaml.NewDecoder(f).Decode(conf) } defer f.Close() return conf,nil }