package database import ( "os" "gopkg.in/yaml.v3" ) type DBOption struct { Host string `yaml:"host"` User string `yaml:"user"` Password string `yaml:"password"` Port string `yaml:"port"` DBName string `yaml:"dbname"` } const ( // 默认的数据库配置文件路径 DefaultConfigPath = "/cfg/db.yaml" ) func LoadDBConfig(path string) (*DBOption, error) { f, err := os.Open(path) if err != nil { return nil, err } defer f.Close() var opt DBOption return &opt, yaml.NewDecoder(f).Decode(&opt) }