# go-gin-template **Repository Path**: mgb/go-gin-template ## Basic Information - **Project Name**: go-gin-template - **Description**: go-gin-template - **Primary Language**: Go - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2025-10-29 - **Last Updated**: 2025-10-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # go-gin-template ## 项目简介 本项目是一个基于 [Gin](https://github.com/gin-gonic/gin) 框架的 Go 语言多主题博客网站模板,支持多主题切换、模板缓存、静态资源管理等功能,适合快速搭建个人博客或企业展示网站。 详细的内容介绍全在微信公众号中。干货持续更新,敬请关注「代码扳手」微信公众号: image ## 目录结构 ``` ├── config.go # 配置加载与环境变量支持 ├── go.mod # Go 依赖管理文件 ├── go.sum # Go 依赖校验文件 ├── main.go # 项目主入口,路由与模板渲染 ├── static/ # 静态资源目录(如 CSS、JS、图片等) │ └── style.css ├── templates/ # 多主题模板目录 │ ├── theme1/ │ │ ├── layouts/ │ │ │ └── base.html │ │ ├── pages/ │ │ │ ├── about.html │ │ │ └── index.html │ │ └── partials/ │ │ ├── footer.html │ │ └── header.html │ └── theme2/ │ └── layouts/ │ └── base.html ``` ## 主要功能 - 支持多主题切换(通过 URL 参数 `theme` 或环境变量设置默认主题) - 模板缓存机制,生产环境下提升渲染性能 - 开发环境下模板热加载,便于调试 - 静态资源自动路由 - 路由示例:`/` 首页,`/about` 关于页 ## 环境变量 - `APP_ENV`:运行环境,`dev`(开发)或 `prod`(生产),默认为 `dev` - `APP_THEME`:默认主题名称,默认为 `theme1` ## 启动方式 1. 安装依赖: ```powershell go mod tidy ``` 2. 启动服务: ```powershell go run main.go ``` 3. 访问网站: - 首页:http://localhost:8080/ - 关于页:http://localhost:8080/about - 切换主题:http://localhost:8080/?theme=theme2 ## 依赖说明 - [Gin](https://github.com/gin-gonic/gin) 高性能 Web 框架 - Go 标准库 `html/template` 用于模板渲染 ## 自定义主题 在 `templates/` 目录下新增主题文件夹,结构需包含 `layouts/`、`pages/`、`partials/`,参考 `theme1`。 ## 许可证 MIT License