goProject/.svn/pristine/7f/7f94cb4684a8f2323d841b58e5517303a5e2b37d.svn-base
2025-01-06 16:21:36 +08:00

63 lines
1.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm"
"Framework/dataSyncMgr/mysqlSync"
"goutil/logUtil"
)
var _ = mysql.DeregisterLocalFile
var (
connectionString = "root:moqikaka3309@tcp(10.1.0.10:3309)/develop_liujun?charset=utf8&parseTime=true&loc=Local&timeout=60s"
maxOpenConns = 10
maxIdleConns = 10
syncFileSize = 1024 * 1024
)
var (
// 数据库对象
dbObj *gorm.DB
// 同步管理对象
syncMgr *mysqlSync.SyncMgr
)
func init() {
// 初始化数据库连接
dbObj = initMysql()
// 构造同步管理对象
syncMgr = mysqlSync.NewSyncMgr(1, "Sync", syncFileSize, 1, dbObj.DB())
}
// 初始化Mysql
func initMysql() *gorm.DB {
dbObj, err := gorm.Open("mysql", connectionString)
if err != nil {
panic(fmt.Errorf("初始化数据库:%s失败错误信息为%s", connectionString, err))
}
logUtil.DebugLog(fmt.Sprintf("连接mysql:%s成功", connectionString))
if maxOpenConns > 0 && maxIdleConns > 0 {
dbObj.DB().SetMaxOpenConns(maxOpenConns)
dbObj.DB().SetMaxIdleConns(maxIdleConns)
}
return dbObj
}
// 注册同步对象
func registerSyncObj(identifier string) {
syncMgr.RegisterSyncObj(identifier)
}
// 保存sql数据
func save(identifier string, command string) {
syncMgr.Save(identifier, command)
}