-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate.go.bak
56 lines (42 loc) · 1.25 KB
/
migrate.go.bak
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
52
53
54
55
56
package main
import (
"bytes"
"github.com/gin-gonic/gin"
// "github.com/gopher-lego/skeleton/app/model"
"github.com/gopher-lego/skeleton/config"
"github.com/jinzhu/gorm"
"github.com/spf13/viper"
)
var AppConfig = viper.New()
func main() {
if gin.Mode() == gin.ReleaseMode {
// https://github.com/go-bindata/go-bindata#accessing-an-asset
filename := "setting/app." + gin.Mode() + ".json"
bytesContent, err := Asset(filename)
if err != nil {
panic("Asset() can not found setting file")
}
// https://github.com/spf13/viper#reading-config-from-ioreader
AppConfig.SetConfigType("json")
if err := AppConfig.ReadConfig(bytes.NewBuffer(bytesContent)); err != nil {
panic("Something error:" + err.Error())
}
} else {
filenameWithoutExt := "app." + gin.Mode()
AppConfig.SetConfigName(filenameWithoutExt)
AppConfig.SetConfigType("json")
AppConfig.AddConfigPath("./setting")
if err := AppConfig.ReadInConfig(); err != nil {
panic("Using config file:" + AppConfig.ConfigFileUsed())
}
}
// Assign config for outside using
config.Set(AppConfig)
// ================================
db := config.MySqlInit()
db.LogMode(true)
panic("Please annotate code below")
// Migrate
// db.AutoMigrate(&model.User{})
defer db.Close()
}