package init_serve import ( _ "dm" dm "dmgorm2" "eta/eta_bridge/global" "fmt" "gorm.io/gorm" "gorm.io/gorm/logger" "io" "log" "os" "time" ) type Product struct { gorm.Model Code string Price uint } func DMDataBase() { mysqlConf := global.CONFIG.Mysql if len(mysqlConf.List) <= 0 { global.LOG.Error("mysql链接未配置") panic(fmt.Errorf("mysql链接未配置")) } //开启日志 logWriter := io.MultiWriter(global.MYSQL_LOG) //binlog日志,记录到文件中去 if global.CONFIG.Mysql.Stdout { logWriter = io.MultiWriter(global.MYSQL_LOG, os.Stdout) } newLogger := logger.New(log.New(logWriter, "\r\n", log.LstdFlags), logger.Config{ SlowThreshold: 200 * time.Millisecond, //慢sql :200ms LogLevel: logger.Info, //记录的日志类型,info代表所有信息都记录 IgnoreRecordNotFoundError: true, //是否忽略找不到数据错误信息(只是日志记录记录成err还是普通的输出的区别,并不影响业务代码中的:找不到数据行error) Colorful: true, //是否颜色输出 }) htConfig := global.CONFIG.HTFutures db, err := gorm.Open(dm.Open(htConfig.OaDBDns), &gorm.Config{ Logger: newLogger, }) if err != nil { global.LOG.Errorf("海通OA数据库 启动异常,数据库:", ";Err:", err) panic(fmt.Errorf("海通OA数据库 启动异常,数据库:", "Err:%s", err)) } global.OaDbHT = db fmt.Println("ht oa database init end") }