Files
go_blog/handlers/admin.go
T
kevin f307781f58 docs: 全部 Go 代码注释汉化
- 48 个 Go 文件所有注释(行注释/块注释/行尾注释,含 _test.go)翻译为中文
- 保留技术标识符:SECURITY_TODO(n)、unsafe-inline、sqlite/mysql、路由参数等
- 代码、字符串字面量、日志消息保持英文原文,零逻辑改动
- go build/vet 通过,go test -count=1 ./... 全绿
2026-08-27 19:03:03 +08:00

36 lines
882 B
Go

package handlers
import (
"net/http"
"github.com/gin-gonic/gin"
"go_blog/models"
"gorm.io/gorm"
)
// AdminDashboard 渲染受保护的管理后台首页。
func AdminDashboard(db *gorm.DB) gin.HandlerFunc {
return func(c *gin.Context) {
tr := getTr(c)
username, _ := c.Get("username")
data := DefaultData(c)
data["Title"] = tr["dash_page_title"]
data["Username"] = username
// 文章数量:总数与已发布数。
var postCount, publishedCount int64
db.Model(&models.Article{}).Count(&postCount)
db.Model(&models.Article{}).Where("status = ?", models.ArticlePublished).Count(&publishedCount)
data["PostCount"] = postCount
data["PublishedCount"] = publishedCount
// 统计卡片中的用户数。
var userCount int64
db.Model(&models.User{}).Count(&userCount)
data["UserCount"] = userCount
c.HTML(http.StatusOK, "dashboard", data)
}
}