user viper

This commit is contained in:
张超
2025-04-15 16:47:00 +08:00
parent 33cb413a12
commit f52d5a698b
12 changed files with 329 additions and 214 deletions

View File

@@ -1,13 +1,17 @@
package controllers
import (
"go_blog/models"
"net/http"
"github.com/gin-gonic/gin"
)
func Home(c *gin.Context) {
c.HTML(http.StatusOK, "home.html", gin.H{
"title": "首页",
var items []models.Content
models.DB.Select("*").Limit(5).Find(&items, "type = ?", "post")
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"Items": items,
})
}

View File

@@ -1,13 +1,20 @@
package controllers
import (
"go_blog/models"
"net/http"
"strconv"
"github.com/gin-gonic/gin"
)
func ShowPost(c *gin.Context) {
c.HTML(http.StatusOK, "home.html", gin.H{
"title": "首页",
})
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)
}