This commit is contained in:
zhangchao
2024-11-11 19:35:24 +08:00
parent f9b330e5a9
commit 67a20f60eb
2 changed files with 15 additions and 3 deletions

16
main.go
View File

@@ -6,6 +6,7 @@ import (
"go_blog/conf"
"go_blog/controllers"
"go_blog/models"
"go_blog/serializers"
"log"
"net/http"
"strconv"
@@ -74,9 +75,20 @@ func esSSE(c *gin.Context) {
func registerRoutes(r *gin.Engine) {
var items []models.Content
models.DB.Select("*").Limit(5).Find(&items, "type = ?", "post")
r.GET("/", func(c *gin.Context) {
var items []models.Content
models.DB.Select("*").Limit(5).Find(&items, "type = ?", "post")
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"Items": items,
})
})
r.GET("/page", func(c *gin.Context) {
var items []models.Content
var pager serializers.Pager
pager.InitPager(c)
offset := (pager.page - 1) * pager.pageSize
models.DB.Select("*").Offset(offset).Limit(pager.pageSize).Find(&items, "type = ?", "post")
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"Items": items,
})