-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (52 loc) · 1.55 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
package main
import (
"embed"
"html/template"
"net/http"
"path"
"github.com/gin-gonic/gin"
"github.com/j1mmyson/reviewList/api"
"github.com/j1mmyson/reviewList/controller"
"github.com/j1mmyson/reviewList/models"
)
var (
//go:embed web/templates/*
templatesFS embed.FS
//go:embed web
staticFS embed.FS
)
func main() {
r := gin.Default()
LoadHTMLFromEmbedFS(r, templatesFS, "web/templates/*")
r.GET("/static/*filepath", func(c *gin.Context) {
c.FileFromFS(path.Join("/web/", c.Request.URL.Path), http.FS(staticFS))
})
models.ConnectDB()
r.GET("/", controller.LogInPage)
r.POST("/", controller.LogIn)
r.GET("/signup", controller.SignUpPage)
r.POST("/signup", controller.SignUp)
r.GET("/logout", controller.LogOut)
r.GET("/dashboard", controller.DashBoardPage)
r.GET("/lists", controller.AllLists)
r.POST("/lists", controller.CreateList)
r.GET("/lists/:user", controller.FindListByUserName)
r.POST("/delete/:id", controller.DeleteListById)
r.POST("/edit/:id", controller.EditListById)
apiRouter := r.Group("/api")
{
apiRouter.POST("/user", api.CreateUser)
apiRouter.GET("/user", api.ShowUserList)
apiRouter.GET("/user/:id", api.GetUser)
apiRouter.DELETE("/user", api.DeleteUser)
apiRouter.GET("/:user_id/card", api.GetCards)
apiRouter.POST("/card", api.CreateCard)
apiRouter.DELETE("/card/:id", api.DeleteCard)
apiRouter.PUT("/card/:id", api.EditCard)
}
r.Run(":8080")
}
func LoadHTMLFromEmbedFS(r *gin.Engine, em embed.FS, pattern string) {
templ := template.Must(template.ParseFS(em, pattern))
r.SetHTMLTemplate(templ)
}