diff --git a/main.go b/main.go index d0cee99..f33ce57 100644 --- a/main.go +++ b/main.go @@ -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) } diff --git a/templates/index.tmpl b/templates/index.tmpl index 70d3806..d6f09c6 100644 --- a/templates/index.tmpl +++ b/templates/index.tmpl @@ -1,118 +1,126 @@
-