我的代码如下
gormDb, err = gorm.Open(mysql.Open(fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", viper.GetString("mysql.username"), viper.GetString("mysql.password"), viper.GetString("mysql.host.write"), viper.GetInt("mysql.port"), viper.GetString("mysql.database"))), &gorm.Config{ SkipDefaultTransaction: true, PrepareStmt: true, }) if err != nil { return err } gormSourceDb, err := gormDb.DB() if err != nil { return err } gormSourceDb.SetMaxIdleConns(viper.GetInt("mysql.max_idle_conns")) gormSourceDb.SetMaxOpenConns(viper.GetInt("mysql.max_open_conns")) return gormDb.Use(dbresolver.Register(dbresolver.Config{ Replicas: []gorm.Dialector{mysql.Open(fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", viper.GetString("mysql.username"), viper.GetString("mysql.password"), viper.GetString("mysql.host.read"), viper.GetInt("mysql.port"), viper.GetString("mysql.database")))}, }))
当我运行服务器时,出现错误:
构建错误: go build -o d:\project cosservic