ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ package gorm import ( "fmt" "github.com/jinzhu/gorm" "project/library/dao/common" "project/library/dao/config" "time" ) type GormMgr struct { Conn *gorm.DB } func InitGorm(cfg *config.MysqlCfg) *GormMgr { conn, err := gorm.Open("mysql", fmt.Sprintf("%s:%s@(%s)/%s?charset=utf8&parseTime=True&loc=Local", cfg.User, cfg.Password, cfg.Addrs, cfg.DBName)) if err != nil { common.SimplePanic("InitGorm失败", err.Error()) } else { conn.DB().SetMaxIdleConns(1024) conn.DB().SetMaxOpenConns(1024) conn.DB().SetConnMaxLifetime(9 * time.Second) } return &GormMgr{Conn: conn} } ~~~