-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
51 lines (40 loc) · 987 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"goshop/front-api/pkg/core/engine"
"goshop/front-api/pkg/core/routerhelper"
"log"
"time"
"github.com/davecgh/go-spew/spew"
"goshop/front-api/pkg/db"
"goshop/front-api/pkg/utils"
_ "goshop/front-api/router"
_ "github.com/jinzhu/gorm/dialects/mysql"
)
func main() {
InitConfig()
routerhelper.InitRouter()
//连接mysql数据库
conn, err := db.GetDbConnect()
if err != nil {
log.Fatalf("mysql 连接失败, %v", err)
}
//把表名的复数形式去掉
conn.SingularTable(true)
//设置mysql的空闲连接数为10个
conn.DB().SetMaxIdleConns(20)
conn.DB().SetMaxOpenConns(1000)
conn.DB().SetConnMaxLifetime(2 * time.Minute)
//连接redis
redisClient, err := db.GetRedisClient()
if err != nil {
log.Fatalf("redis 连接失败, %v", err)
}
defer func() {
err = conn.Close()
spew.Dump(err, "mysql")
err = redisClient.Close()
spew.Dump(err, "redis")
}()
initService()
log.Fatal(engine.R.Run(utils.C.Base.Webhost))
}