-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
84 lines (70 loc) · 1.35 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
package main
import (
"embed"
"fmt"
"os"
"os/signal"
"time"
"github.com/jessevdk/go-flags"
"github.com/samber/lo"
"sealchat/api"
"sealchat/model"
"sealchat/pm"
"sealchat/utils"
)
//go:embed ui/dist
var embedDirStatic embed.FS
//go:generate go run ./pm/generator/
func main() {
var opts struct {
Install bool `short:"i" long:"install" description:"安装为系统服务"`
Uninstall bool `long:"uninstall" description:"删除系统服务"`
Download bool `short:"d" long:"download" description:"从github下载最新的压缩包"`
}
_, err := flags.ParseArgs(&opts, os.Args)
if err != nil {
return
}
if opts.Install {
serviceInstall(true)
return
}
if opts.Uninstall {
serviceInstall(false)
return
}
if opts.Download {
err = downloadLatestRelease()
if err != nil {
fmt.Println(err.Error())
}
return
}
lo.Must0(os.MkdirAll("./data", 0755))
config := utils.ReadConfig()
model.DBInit(config.DSN)
cleanUp := func() {
if db := model.GetDB(); db != nil {
if sqlDB, err := db.DB(); err == nil {
_ = sqlDB.Close()
}
}
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
_ = <-c
cleanUp()
os.Exit(0)
}()
pm.Init()
autoSave := func() {
t := time.NewTicker(3 * 60 * time.Second)
for {
<-t.C
model.FlushWAL()
}
}
go autoSave()
api.Init(config, embedDirStatic)
}