-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (39 loc) · 1.01 KB
/
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 (
"dromatech/pos-backend/app"
"dromatech/pos-backend/config"
"dromatech/pos-backend/global"
"fmt"
"os"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"github.com/sirupsen/logrus"
)
func main() {
fmt.Println("POS Backend v1.0.10")
// load configuration
fmt.Println("Load Configuration")
cfg, err := config.New("config.yaml")
if err != nil {
fmt.Println(err.Error())
}
global.CONFIG = cfg
// set up log
f, err := os.OpenFile(cfg.LogConfig.LogFilename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0755)
if err != nil {
logrus.Fatal(err)
}
logrus.SetOutput(f)
logrus.SetFormatter(&logrus.JSONFormatter{})
// set up database
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable", cfg.Database.Host, cfg.Database.User, cfg.Database.Password, cfg.Database.DBName, cfg.Database.Port)
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
logrus.Fatal(err)
}
global.DBCON = db
err = app.StartApp()
if err != nil {
logrus.Error(err.Error())
}
}