-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
85 lines (60 loc) · 2.1 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
78
79
80
81
82
83
84
85
package main
import (
"log"
"time"
"usermanagement/controller"
"usermanagement/model"
"usermanagement/utils"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/session"
"github.com/gofiber/template/html/v2"
)
func main() {
// godotenv package
WEB_PORT := utils.DotEnvVariable(utils.WEB_PORT)
model.ConnectDb()
// Create a new engine
engine := html.New("./views", ".html")
// Or from an embedded system
// See github.com/gofiber/embed for examples
// engine := html.NewFileSystem(http.Dir("./views", ".html"))
// Pass the engine to the Views
app := fiber.New(fiber.Config{
Views: engine,
})
/* Sessions Config */
utils.Store = session.New(session.Config{
CookieHTTPOnly: true,
// CookieSecure: true, for https
Expiration: time.Hour * 1,
})
// Serve static files (HTML templates and stylesheets).
app.Static("/", "./assets")
/* Views */
app.Get("/401", controller.GET401ViewCreatePage)
app.Get("/404", controller.GET404ViewCreatePage)
app.Get("/500", controller.GET500ViewCreatePage)
app.Get("/login", controller.GETLoginViewCreatePage)
app.Post("/login", controller.POSTLoginViewCreatePage)
app.Get("/register", controller.GETRegisterViewCreatePage)
app.Post("/register", controller.POSTRegisterViewCreatePage)
app.Get("/", controller.GETIndexViewCreatePage)
/* Views protected with session middleware */
adminApp := app.Group("/", controller.AuthMiddleware)
/* todoApp.Get("/list", HandleViewList)
todoApp.Get("/create", HandleViewCreatePage)
todoApp.Post("/create", HandleViewCreatePage)
todoApp.Get("/edit/:id", HandleViewEditPage)
todoApp.Post("/edit/:id", HandleViewEditPage) */
adminApp.Get("/dashboard", controller.GETDashboardViewCreatePage)
adminApp.Get("/profile", controller.GETProfileViewCreatePage)
adminApp.Get("/all-users", controller.GETAllUsersViewCreatePage)
adminApp.Get("/delete", controller.GETDeleteUser)
adminApp.Get("/logout", controller.GETLogoutPage)
// a custom 404 handler at router tail
app.Use(func(ctx *fiber.Ctx) error {
ctx.Status(404).Render("404", fiber.Map{})
return nil
})
log.Fatal(app.Listen(":" + WEB_PORT))
}