-
Notifications
You must be signed in to change notification settings - Fork 48
/
main.go
70 lines (60 loc) · 1.58 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
package main
import (
"embed"
"fmt"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"message-nest/migrate"
"message-nest/models"
"message-nest/pkg/constant"
"message-nest/pkg/logging"
"message-nest/pkg/setting"
"message-nest/routers"
"message-nest/service/cron_msg_service"
"message-nest/service/cron_service"
"net/http"
"os"
)
var (
//go:embed web/dist/*
f embed.FS
//go:embed .release*
rf embed.FS
)
func init() {
constant.InitReleaseInfo(rf)
setting.Setup()
logging.Setup()
migrate.Setup()
models.Setup()
}
func main() {
cron_service.StartLogsCronRun()
cron_msg_service.StartUpMsgCronTask()
gin.SetMode(setting.ServerSetting.RunMode)
routersInit := routers.InitRouter(f)
readTimeout := setting.ServerSetting.ReadTimeout
writeTimeout := setting.ServerSetting.WriteTimeout
endPoint := fmt.Sprintf(":%d", setting.ServerSetting.HttpPort)
maxHeaderBytes := 1 << 20
server := &http.Server{
Addr: endPoint,
Handler: routersInit,
ReadTimeout: readTimeout,
WriteTimeout: writeTimeout,
MaxHeaderBytes: maxHeaderBytes,
}
startInfo := ""
if setting.ServerSetting.RunMode == "debug" {
startInfo = fmt.Sprintf("run mode: %s, start message server @ http://localhost%s", setting.ServerSetting.RunMode, endPoint)
} else {
startInfo = fmt.Sprintf("run mode: %s, start message server @ http://0.0.0.0%s", setting.ServerSetting.RunMode, endPoint)
}
logrus.WithFields(logrus.Fields{
"prefix": fmt.Sprintf("[PID:%d]", os.Getpid()),
}).Infof(startInfo)
err := server.ListenAndServe()
if err != nil {
logrus.Errorf("Server err: ", err)
}
}