add post page

This commit is contained in:
张超
2024-08-05 17:19:23 +08:00
parent e974da8adb
commit bfa17eaf13
6 changed files with 125 additions and 151 deletions

20
main.go
View File

@@ -6,6 +6,7 @@ import (
"go_blog/controllers"
"go_blog/models"
"net/http"
"strconv"
"github.com/gin-gonic/gin"
)
@@ -60,15 +61,17 @@ func registerRoutes(r *gin.Engine) {
r.GET("/createcontent", func(c *gin.Context) {
c.HTML(http.StatusOK, "content.tmpl", nil)
})
user := getUserInfo()
r.GET("/page/:id", func(c *gin.Context) {
id := c.Param("id")
c.HTML(http.StatusOK, "page"+id+".tmpl", map[string]interface{}{
"title": "这个是titile,传入templates中的",
"user": getUserInfo,
})
})
r.GET("/post/:id", func(c *gin.Context) {
id, err := strconv.ParseInt(c.Param("id"), 10, 32)
if err != nil {
return
}
var content = models.Content{Cid: int32(id)}
models.DB.First(&content)
c.HTML(http.StatusOK, "post.tmpl", content)
})
user := getUserInfo()
r.GET("/login", func(c *gin.Context) {
c.HTML(200, "login.tmpl", map[string]interface{}{
"title": "这个是titile,传入templates中的",
@@ -77,7 +80,6 @@ func registerRoutes(r *gin.Engine) {
})
r.GET("/ws", controllers.WebSocketHandler)
r.POST("/content", controllers.CreateContentHandler)
r.POST("/login", controllers.UsersLoginHandler)
}