MCPcopy Create free account
hub / github.com/LockGit/gochat / initDB

Function initDB

db/db.go:25–42  ·  view source on GitHub ↗
(dbName string)

Source from the content-addressed store, hash-verified

23}
24
25func initDB(dbName string) {
26 var e error
27 // if prod env , you should change mysql driver for yourself !!!
28 realPath, _ := filepath.Abs("./")
29 configFilePath := realPath + "/db/gochat.sqlite3"
30 syncLock.Lock()
31 dbMap[dbName], e = gorm.Open("sqlite3", configFilePath)
32 dbMap[dbName].DB().SetMaxIdleConns(4)
33 dbMap[dbName].DB().SetMaxOpenConns(20)
34 dbMap[dbName].DB().SetConnMaxLifetime(8 * time.Second)
35 if config.GetMode() == "dev" {
36 dbMap[dbName].LogMode(true)
37 }
38 syncLock.Unlock()
39 if e != nil {
40 logrus.Error("connect db fail:%s", e.Error())
41 }
42}
43
44func GetDb(dbName string) (db *gorm.DB) {
45 if db, ok := dbMap[dbName]; ok {

Callers 1

initFunction · 0.85

Calls 1

GetModeFunction · 0.92

Tested by

no test coverage detected