mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Testing for controller/main.go
This commit is contained in:
34
models/init.go
Normal file
34
models/init.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"Cloudreve/pkg/util"
|
||||
"github.com/jinzhu/gorm"
|
||||
"time"
|
||||
|
||||
//
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
)
|
||||
|
||||
// DB 数据库链接单例
|
||||
var DB *gorm.DB
|
||||
|
||||
// Database 在中间件中初始化mysql链接
|
||||
func Database(connString string) {
|
||||
db, err := gorm.Open("mysql", connString)
|
||||
db.LogMode(true)
|
||||
// Error
|
||||
if err != nil {
|
||||
util.Log().Panic("连接数据库不成功", err)
|
||||
}
|
||||
//设置连接池
|
||||
//空闲
|
||||
db.DB().SetMaxIdleConns(50)
|
||||
//打开
|
||||
db.DB().SetMaxOpenConns(100)
|
||||
//超时
|
||||
db.DB().SetConnMaxLifetime(time.Second * 30)
|
||||
|
||||
DB = db
|
||||
|
||||
migration()
|
||||
}
|
||||
Reference in New Issue
Block a user