-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinitializer.go
61 lines (52 loc) · 1.38 KB
/
initializer.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
52
53
54
55
56
57
58
59
60
61
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"spike/config"
"spike/helps/configurations"
"spike/models"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
const database = "sqlite3"
func init() {
var confFile string
var pidFile string
flag.Usage = func() {
fmt.Println("Usage: " + os.Args[0] + " [options]\n\nOptions:")
fmt.Println("\t-conf \t the configuration file. (Default: app.conf)")
fmt.Println("\t-pid \t the pid file. (Default: app.pid)")
}
flag.StringVar(&confFile, "conf", "app.conf", "path to configuration file.")
flag.StringVar(&pidFile, "pid", "app.pid", "path to pid file.")
flag.Parse()
absConfPath, _ := filepath.Abs(confFile)
absPidPath, _ := filepath.Abs(pidFile)
appConfig = &config.ApplicationConfig{}
// load configuration
parser := &configurations.TomlParser{}
err := parser.LoadConfiguration(appConfig, absConfPath)
if err != nil {
fmt.Println(err.Error())
}
//// init the mysql
//mysqlDB, err = connection_pool.NewMysql(appConfig.Mysql)
//if err != nil {
// panic(err.Error())
//}
sqlite, err = gorm.Open(database, appConfig.Sqlite)
if err != nil {
fmt.Println(err.Error())
}
sqlite.AutoMigrate(
&models.MicroService{},
&models.GpgKey{},
&models.User{},
)
if err := ioutil.WriteFile(absPidPath, []byte(fmt.Sprintf("%d", os.Getpid())), 0644); err != nil {
fmt.Println(err.Error())
}
}