-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
56 lines (44 loc) · 1.11 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
package main
import (
"embed"
"fmt"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/pxgo/GoFM/middlewares"
"github.com/pxgo/GoFM/modules"
"github.com/pxgo/GoFM/routes"
"io/fs"
"net/http"
"os"
)
//go:embed web/dist/*
var publicFiles embed.FS
func main() {
modules.InitReader()
e := echo.New()
e.HideBanner = true
e.HTTPErrorHandler = middlewares.CustomHTTPErrorHandler
e.Use(middlewares.LoggerIn)
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
}))
var fileSystem http.FileSystem
if modules.Config.Debug {
fileSystem = http.FS(os.DirFS("web/dist"))
} else {
fsys, err := fs.Sub(publicFiles, "web/dist")
if err != nil {
modules.Logger.Error(err)
panic(err)
}
fileSystem = http.FS(fsys)
}
assetHandler := http.FileServer(fileSystem)
routes.InitRoutes(e)
e.GET("/*", echo.WrapHandler(assetHandler))
err := e.Start(fmt.Sprintf("%s:%d", modules.Config.Host, modules.Config.Port))
if err != nil {
modules.Logger.Error(err)
}
}