-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
46 lines (42 loc) · 962 Bytes
/
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 (
"embed"
"fmt"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"horizon/config"
"horizon/model"
"horizon/router"
"horizon/tasks"
"horizon/utils"
"html/template"
"io/fs"
"net/http"
)
//go:embed static
var Static embed.FS
func init() {
help := utils.HelpInit()
config.InitConfig(help.ConfigFile)
utils.LogInit()
model.InitDb()
}
func main() {
var r *gin.Engine
if config.Conf.General.Environment == "dev" {
r = router.InitRouter()
} else {
// init prod router
r = router.InitRouterPack()
// load frontend
sub, _ := fs.Sub(Static, "static")
r.StaticFS("/static", http.FS(sub))
// load index.html template
staticTemplate := template.Must(template.New("").ParseFS(Static, "static/*.html"))
r.SetHTMLTemplate(staticTemplate)
}
tasks.InitTasks()
log.Infof("start horizon in :%d", config.Conf.General.Port)
err := r.Run(fmt.Sprintf(":%d", config.Conf.General.Port))
log.Fatal(err.Error())
}