From 7a213e6e76b795102d286ce97ca66851cc2b62f6 Mon Sep 17 00:00:00 2001 From: huanghua_2017 <550329393@qq.com> Date: Fri, 1 Feb 2019 15:29:52 +0800 Subject: [PATCH] =?UTF-8?q?mysql=20=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=B1=A0=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sysmodule/DBModule.go | 6 +++++- sysmodule/DBModule_test.go | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sysmodule/DBModule.go b/sysmodule/DBModule.go index 55c7ab1..9ff070c 100644 --- a/sysmodule/DBModule.go +++ b/sysmodule/DBModule.go @@ -206,7 +206,7 @@ func (slf *DBResult) mapSlice2interface(data []map[string]string, in interface{} } // Connect ... -func (slf *DBModule) Connect() error { +func (slf *DBModule) Connect(maxConn int) error { cmd := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true&loc=%s", slf.UserName, slf.Password, @@ -225,6 +225,10 @@ func (slf *DBModule) Connect() error { return err } slf.db = db + db.SetMaxOpenConns(maxConn) + db.SetMaxIdleConns(maxConn) + db.SetConnMaxLifetime(time.Second * 90) + return nil } diff --git a/sysmodule/DBModule_test.go b/sysmodule/DBModule_test.go index f7582a4..d60b192 100644 --- a/sysmodule/DBModule_test.go +++ b/sysmodule/DBModule_test.go @@ -14,7 +14,7 @@ func TestDBModule(t *testing.T) { Password: "Root!!2018", DBName: "QuantFundsDB", } - db.Connect() + db.Connect(100) res := db.Query("select * from tbl_fun_heelthrow where id >= 1") if res.Err != nil { @@ -26,7 +26,7 @@ func TestDBModule(t *testing.T) { Uuid string `json:"uuid,omitempty"` AAAA string `json:"xxx"` }{} - err := res.SetSpecificTag("json").SetBlurMode(false).UnMarshal(&out) + err := res.SetSpecificTag("json").SetBlurMode(true).UnMarshal(&out) if err != nil { t.Error(err) }