-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
89 lines (74 loc) · 2.18 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
_ "embed"
"fmt"
"os"
"time"
_ "github.com/go-sql-driver/mysql"
log "github.com/sirupsen/logrus"
"github.com/wailsapp/wails"
"gorm.io/driver/mysql"
"gorm.io/gorm"
gormLogger "gorm.io/gorm/logger"
"github.com/hinha/todo-desktop-app/backend/domain"
_noteBookRepo "github.com/hinha/todo-desktop-app/backend/note/repository/mysql"
_noteBookService "github.com/hinha/todo-desktop-app/backend/note/service"
"github.com/hinha/todo-desktop-app/backend/server"
)
func basic() string {
return "World!"
}
//go:embed frontend/build/static/js/main.js
var js string
//go:embed frontend/build/static/css/main.css
var css string
func main() {
var (
//appSecret = envString("APP_SECRET", "secret")
dbUser = envString("DB_USER", "user")
dbPass = envString("DB_PASS", "password")
dbName = envString("DB_NAME", "admin")
dbHost = envString("DB_HOST", "127.0.0.1")
)
logger := log.New()
logger.Formatter = new(log.TextFormatter)
logger.Formatter.(*log.TextFormatter).DisableColors = true
logger.Formatter.(*log.TextFormatter).FullTimestamp = true
logger.Level = log.TraceLevel
logger.WithField("ts", logger.WithTime(time.Now()))
dsn := fmt.Sprintf("%s:%s@tcp(%s:3306)/%s?charset=utf8mb4&parseTime=True&loc=Local", dbUser, dbPass, dbHost, dbName)
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
Logger: gormLogger.Default.LogMode(gormLogger.Silent),
})
if err != nil {
log.Fatal(err.Error())
}
if err := db.AutoMigrate(&domain.User{}, &domain.Notebook{}, &domain.Note{}, &domain.Category{}, &domain.NoteStatus{}); err != nil {
panic(err)
}
// Repository
noteBookRepo := _noteBookRepo.New(db)
// Service/Uses case
noteBookService := _noteBookService.NewNoteBookService(noteBookRepo)
noteBookService = _noteBookService.NewNotebookLogger(logger.WithField("component", "notebook"), noteBookService)
// Serve
srv := server.New(&wails.AppConfig{
Width: 1024,
Height: 768,
Title: "Keep",
JS: js,
CSS: css,
Colour: "#ffffff",
Resizable: true,
MinWidth: 680,
MinHeight: 560,
}, noteBookService)
srv.Run()
}
func envString(env, fallback string) string {
e := os.Getenv(env)
if e == "" {
return fallback
}
return e
}