-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (40 loc) · 913 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
package main
import (
"GoStarter/config"
"GoStarter/controller"
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
"github.com/sirupsen/logrus"
)
func main() {
logrus.SetLevel(logrus.DebugLevel)
// Disable Console Color
//gin.DisableConsoleColor()
gin.SetMode(gin.DebugMode)
//gin.SetMode(gin.ReleaseMode)
config := config.FromFile("./config/config.json")
c := controller.New(config)
logrus.Fatal(c.Start())
}
func initDB(config config.Main) (*gorm.DB, error) {
db, err := gorm.Open("mysql", config.DbConnURL())
if err != nil {
return nil, err
}
if err := db.DB().Ping(); err != nil {
return nil, err
}
if config.Debug.DB {
db = db.Debug()
}
/*
migrations := &migrate.FileMigrationSource{
Dir: "db/migrations",
}
if _, err := migrate.Exec(db.DB(), "mysql", migrations, migrate.Up); err != nil {
return nil, err
}
*/
db.DB().SetMaxOpenConns(100)
return db, nil
}