package config import ( "gopkg.in/yaml.v2" "os" "sync" ) var ( instance *config once sync.Once ) func init() { once.Do(func() { var conf config path, _ := os.Getwd() filePath := path + "/config/config.yaml" if f, err := os.Open(filePath); err != nil { panic(err) } else { err := yaml.NewDecoder(f).Decode(&conf) if err != nil { panic(err) } } instance = &conf }) } //获取配置文档实例 func Instance() *config { return instance } type config struct { Server server `yaml:"server"` Database database `yaml:"database"` Redis redis `yaml:"redis"` Logger logger `yaml:"logger"` Minio minio `yaml:"minio"` Foreign foreign `yaml:"foreign"` } type server struct { Address string `yaml:"address"` CodeEnabled bool `yaml:"code_enabled"` TokenSign string `yaml:"token_sign"` } type database struct { Host string `yaml:"host"` User string `yaml:"user"` Password string `yaml:"password"` Port string `yaml:"port"` Name string `yaml:"name"` Timezone string `yaml:"timezone"` } type redis struct { Host string `yaml:"host"` Password string `yaml:"password"` } type logger struct { Path string `yaml:"path"` Name string `yaml:"name"` Level string `yaml:"level"` } type minio struct { Endpoint string `yaml:"endpoint"` Link string `yaml:"link"` AccessKey string `yaml:"access_key"` SecretKey string `yaml:"secret_key"` } type foreign struct { IotEdgeUrl string `yaml:"iot_edge_url"` SecurityRewindUrl string `yaml:"security_rewind_url"` }