github.com/qiuhoude/go-web@v0.0.0-20220223060959-ab545e78f20d/blogweb_gin/controllers/show_article_controller.go (about) 1 package controllers 2 3 import ( 4 "github.com/gin-gonic/gin" 5 "github.com/qiuhoude/go-web/blogweb_gin/logs" 6 "github.com/qiuhoude/go-web/blogweb_gin/models" 7 "github.com/qiuhoude/go-web/blogweb_gin/utils" 8 "net/http" 9 "strconv" 10 ) 11 12 // 显示文章 13 func ShowArticleGet(c *gin.Context) { 14 islogin := GetSession(c) 15 16 idStr := c.Param("id") 17 id, _ := strconv.Atoi(idStr) 18 logs.Info.Println("id:", id) 19 20 //获取id所对应的文章信息 21 art := models.QueryArticleWithId(id) 22 contentHTML := utils.SwitchMarkdownToHtml(art.Content) 23 24 //渲染HTML 25 c.HTML(http.StatusOK, "show_article.html", gin.H{"IsLogin": islogin, "Title": art.Title, "Content": contentHTML}) 26 }