-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (59 loc) · 1.34 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
74
75
76
77
package main
import (
"catmash/controllers"
"catmash/daos"
"catmash/routes"
"catmash/utils"
"os"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"golang.org/x/crypto/acme/autocert"
)
/*
HEY BRO' !!!!
DON'T FORTGET YOU HAVE TO :
-SECURE API
*/
var (
dbDao daos.DAO
)
func init() {
utils.LoadEnv()
dbDao.Server = os.Getenv("DB_SERVER")
dbDao.Database = os.Getenv("DB_NAME")
connectDb()
}
func connectDb() {
dbDao.Connect()
controllers.Dao = &dbDao
}
func main() {
/* App instance */
e := echo.New()
/* HTTPS redirection */
e.Pre(middleware.HTTPSWWWRedirect())
/* loger */
e.Use(middleware.LoggerWithConfig(middleware.DefaultLoggerConfig))
e.Use(middleware.Recover())
e.Use(middleware.Secure())
e.Use(middleware.Gzip())
/* Bind routes */
routes.SetRoutes(e)
//If prod is true in .env file
if os.Getenv("PROD") == "true" {
// dns autorisation
e.AutoTLSManager.HostPolicy = autocert.HostWhitelist("catmash.tk", "www.catmash.tk")
// cache file
e.AutoTLSManager.Cache = autocert.DirCache("/var/www/.cache")
// Http server
go func(c *echo.Echo) {
// https redirection
e.Pre(middleware.HTTPSRedirect())
e.Logger.Fatal(e.Start(os.Getenv("HTTP")))
}(e)
// Https server
e.Logger.Fatal(e.StartAutoTLS(os.Getenv("HTTPS")))
} else {
e.Logger.Fatal(e.Start(os.Getenv("HTTP")))
}
}