package config import ( "github.com/Unknwon/goconfig" "log" "os" ) type MysqlConf struct { User string Passwd string Conn string } func (m *MysqlConf) GetMysqlConn() { var cfg *goconfig.ConfigFile cpath, _ := os.Getwd() config, err := goconfig.LoadConfigFile(cpath + "/config/config.ini") //加载配置文件 if err != nil { log.Println("get config file error") os.Exit(-1) } cfg = config glob, _ := cfg.GetSection("mysql") //读取全部mysql配置 m.User, _ = glob["username"] m.Passwd, _ = glob["password"] m.Conn, _ = glob["url"] }