add page
This commit is contained in:
2
go.mod
2
go.mod
@@ -3,6 +3,7 @@ module go_blog
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/fsnotify/fsnotify v1.7.0
|
||||
github.com/gin-gonic/gin v1.9.1
|
||||
github.com/go-ini/ini v1.67.0
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible
|
||||
@@ -12,7 +13,6 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-sql-driver/mysql v1.7.0 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
|
||||
14
main.go
14
main.go
@@ -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) {
|
||||
|
||||
r.GET("/", func(c *gin.Context) {
|
||||
var items []models.Content
|
||||
models.DB.Select("*").Limit(5).Find(&items, "type = ?", "post")
|
||||
r.GET("/", func(c *gin.Context) {
|
||||
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,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user