feat(model): 添加时间工具函数并在首页模板中使用

- 新增 model 包下 time.go,提供时间戳转换和获取当前时间戳的多种方法
- 新增 model 包下 tools.go,包含 UnixToTime 函数用于时间戳格式化
- 在 main.go 中注册 UnixToTime 为模板函数
- 修改默认控制器,首页渲染中添加时间戳数据及标题
- 首页模板添加调用 UnixToTime 格式化显示时间戳
- 优化控制器导入,添加必要包引用和格式调整
This commit is contained in:
2026-02-22 14:17:17 +08:00
parent b7b0c32e82
commit ae36d59b68
5 changed files with 74 additions and 3 deletions

View File

@@ -1,7 +1,9 @@
package main
import (
"awesomeProject/model"
"awesomeProject/router"
"html/template"
"github.com/gin-gonic/gin"
)
@@ -11,6 +13,11 @@ func main() {
// 创建默认的gin引擎
r := gin.Default()
//自定义模板函数
r.SetFuncMap(template.FuncMap{
"UnixToTime": model.UnixToTime,
})
// 加载模板文件,支持多层目录结构
r.LoadHTMLGlob("templates/**/*")