我把mysql信息从配置文件读出来。mysql主机,用户,密码和数据库名称怎么作为变量传到sql.open()?
cfg, err := ini.Load("setting.ini")
//cfg.BlockMode = false
if err != nil {
panic(err)
}
mysqlhost := cfg.Section("mysql").Key("host").String()
mysqluser := cfg.Section("mysql").Key("user").String()
mysqlpassword := cfg.Section("mysql").Key("password").String()
mysqldatabase := cfg.Section("mysql").Key("database").String()
dbconn, err = sql.Open("mysql", "%s:%s@tcp(%s)/%s?charset=utf8&parseTime=True&loc=Local")