ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ package sqlx import ( "fmt" "github.com/jmoiron/sqlx" "project/library/dao/common" "project/library/dao/config" "time" ) type SqlxMgr struct { Conn *sqlx.DB } func InitSqlx(cfg *config.MysqlCfg) *SqlxMgr { conn, err := sqlx.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.SetMaxIdleConns(1024) conn.SetMaxOpenConns(1024) conn.SetConnMaxLifetime(9 * time.Second) } return &SqlxMgr{Conn: conn} } ~~~