-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (44 loc) · 1.2 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
package main
import (
"fmt"
"html/template"
"net/http"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
"toggle-corp/coding-challenges/internal/globals"
"toggle-corp/coding-challenges/internal/middleware"
"toggle-corp/coding-challenges/internal/routers"
"toggle-corp/coding-challenges/internal/utils"
)
func main() {
db, err := utils.ConnectDB()
if err != nil {
fmt.Println(err)
return
}
r := gin.Default()
r.SetFuncMap(template.FuncMap{
"formatAsDate": utils.FormatAsDate,
"snakeToTitle": utils.SnakeToTitle,
})
r.LoadHTMLGlob("templates/*.html")
r.Delims("{{", "}}")
r.Use(sessions.Sessions("session", cookie.NewStore(globals.Secret)))
public := r.Group("/")
routers.PublicRoutes(public, db)
private := r.Group("/")
private.Use(middleware.AuthRequired(db))
routers.PrivateRoutes(private, db)
if utils.GetOSEnv("GIN_MODE", "local") == "release" {
// get key and cert
// r.RunTLS("0.0.0.0:443", "./server.cert", "./server.keys")
err := http.ListenAndServeTLS("0.0.0.0:443", "/certs/server.cert", "/certs/server.key", r)
if err != nil {
fmt.Println("Could not start WebServer")
fmt.Println(err)
}
} else {
r.Run()
}
}