-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
76 lines (56 loc) · 1.56 KB
/
main.go
File metadata and controls
76 lines (56 loc) · 1.56 KB
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
package main
import (
"Gooo/constants"
"Gooo/handlers"
"Gooo/helpers/gooo"
customMiddleware "Gooo/helpers/middleware"
"log"
"os"
"github.com/joho/godotenv"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func main() {
envFile := os.Getenv("ENV_FILE")
if envFile == "" {
envFile = ".env"
}
if err := godotenv.Load(envFile); err != nil {
log.Printf("WARNING: Couldn't load %s file: %v", envFile, err)
}
log.SetFlags(0)
log.Println("")
log.Printf("\u2022 Environment: %s%s%s%s", constants.Blue, constants.Bold, os.Getenv("ENV"), constants.Reset)
e := echo.New()
appPort := os.Getenv("APP_PORT")
if appPort == "" {
// Fallback for some deployment services create their own ports
appPort = os.Getenv("PORT")
}
if appPort == "" {
log.Fatal("APP_PORT env variable not set correctly")
}
e.Use(customMiddleware.ThemeMiddleware)
e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
Level: 5,
}))
e.GET("/", handlers.HomeHandler)
e.GET("/get-started", handlers.GetStarted)
e.GET("/guide", handlers.Guide)
e.GET("/install", handlers.Install)
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return customMiddleware.EnvMiddleware(next, os.Getenv("ENV"))
})
// Serve Static Assets for Production
isLocal := os.Getenv("ENV") == "DEV"
if !isLocal {
e.Static("/static", "static")
e.Static("/gen", "gen")
} else {
gooo.HandleViteDevServer(e, isLocal)
}
e.Static("/static", "static")
e.File("/favicon.ico", "static/favicon.ico")
gooo.HandleServerReload(e, isLocal)
e.Logger.Fatal(e.Start(":" + appPort))
}