forked from 1340691923/ElasticView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
73 lines (60 loc) · 1.92 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
package main
import (
"flag"
"github.com/1340691923/ElasticView/application"
"github.com/1340691923/ElasticView/engine/logs"
"github.com/1340691923/ElasticView/router"
"log"
"os"
"os/signal"
"strconv"
"syscall"
_ "github.com/go-sql-driver/mysql"
"go.uber.org/zap"
)
var (
appName string
configFileDir string
configFileName string
configFileExt string
)
func init() {
flag.StringVar(&appName, "appName", "ElasticView", "应用名")
flag.StringVar(&configFileDir, "configFileDir", "config", "配置文件夹名")
flag.StringVar(&configFileName, "configFileName", "config", "配置文件名")
flag.StringVar(&configFileExt, "configFileExt", "json", "配置文件后缀")
flag.Parse()
}
// By 肖文龙
func main() {
app := application.NewApp(
application.WithAppName(appName),
application.WithConfigFileDir(configFileDir),
application.WithConfigFileName(configFileName),
application.WithConfigFileExt(configFileExt),
application.RegisterInitFnObserver(application.InitLogs),
application.RegisterInitFnObserver(application.InitMysql),
application.RegisterInitFnObserver(application.InitTask),
application.RegisterInitFnObserver(application.InitRbac),
application.RegisterInitFnObserver(application.InitOpenWinBrowser),
)
err := app.InitConfig().NotifyInitFnObservers().Error()
if err != nil {
logs.Logger.Error("ElasticView 初始化失败", zap.String("err.Error()", err.Error()))
panic(err)
}
port := ":" + strconv.Itoa(application.GlobConfig.Port)
appServer := router.Init()
go func() {
if err := appServer.Listen(port); err != nil {
logs.Logger.Error("ElasticView http服务启动失败:", zap.String("err.Error()", err.Error()))
log.Panic(err)
}
}()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c
logs.Logger.Info("ElasticView http服务停止中...")
// 这里进行任务释放操作
logs.Logger.Info("ElasticView http服务停止成功...")
}