add page
This commit is contained in:
2
go.mod
2
go.mod
@@ -3,6 +3,7 @@ module go_blog
|
|||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/fsnotify/fsnotify v1.7.0
|
||||||
github.com/gin-gonic/gin v1.9.1
|
github.com/gin-gonic/gin v1.9.1
|
||||||
github.com/go-ini/ini v1.67.0
|
github.com/go-ini/ini v1.67.0
|
||||||
github.com/golang-jwt/jwt v3.2.2+incompatible
|
github.com/golang-jwt/jwt v3.2.2+incompatible
|
||||||
@@ -12,7 +13,6 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
|
||||||
github.com/go-sql-driver/mysql v1.7.0 // indirect
|
github.com/go-sql-driver/mysql v1.7.0 // indirect
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
|
|||||||
16
main.go
16
main.go
@@ -6,6 +6,7 @@ import (
|
|||||||
"go_blog/conf"
|
"go_blog/conf"
|
||||||
"go_blog/controllers"
|
"go_blog/controllers"
|
||||||
"go_blog/models"
|
"go_blog/models"
|
||||||
|
"go_blog/serializers"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -74,9 +75,20 @@ func esSSE(c *gin.Context) {
|
|||||||
|
|
||||||
func registerRoutes(r *gin.Engine) {
|
func registerRoutes(r *gin.Engine) {
|
||||||
|
|
||||||
var items []models.Content
|
|
||||||
models.DB.Select("*").Limit(5).Find(&items, "type = ?", "post")
|
|
||||||
r.GET("/", func(c *gin.Context) {
|
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{
|
c.HTML(http.StatusOK, "index.tmpl", gin.H{
|
||||||
"Items": items,
|
"Items": items,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user