qoder优化。
This commit is contained in:
@@ -44,7 +44,11 @@ func Home(c *gin.Context) {
|
||||
}
|
||||
|
||||
var items []models.Content
|
||||
db.Select("*").Limit(5).Find(&items, "type = ?", "post")
|
||||
result := db.Select("*").Limit(5).Find(&items, "type = ?", "post")
|
||||
if result.Error != nil {
|
||||
c.String(http.StatusInternalServerError, "Database error: "+result.Error.Error())
|
||||
return
|
||||
}
|
||||
|
||||
tpl := themeManager.GetTemplate("index")
|
||||
if tpl == nil {
|
||||
@@ -52,9 +56,13 @@ func Home(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||
tpl.Execute(c.Writer, gin.H{
|
||||
data := gin.H{
|
||||
"Items": items,
|
||||
"Title": "首页",
|
||||
})
|
||||
}
|
||||
|
||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||
if err := tpl.Execute(c.Writer, data); err != nil {
|
||||
c.String(http.StatusInternalServerError, "Template render error: "+err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user