gin 页面重定向
2024-10-20 16:48:30
两种gin页面重定向方式
redirect:
package main import (
"github.com/gin-gonic/gin"
"net/http"
) func main() { r := gin.Default() r.GET("/redirect", func(c *gin.Context) {
c.Redirect(http.StatusMovedPermanently,"http://www.baidu.com")
}) r.Run(":8080")
}
html rendering:
func main() {
router := gin.Default()
router.LoadHTMLGlob("templates/*") router.GET("/index", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"title": "Main website",
})
})
router.Run(":8080")
}
其中
router.LoadHTMLGlob("templates/*")是设置前端页面目录
最新文章
- Improve Your Study Habits
- Java NIO 之缓冲区
- 再看静态static及相关知识汇集
- jenkins2 pipeline介绍
- 详解Paint的setMaskFilter(MaskFilter maskfilter)
- 书写CSS需要注意的地方
- java ant 命令大全
- [LeetCode] Largest Rectangle in Histogram 解题思路
- Nginx fastcgi_param解释
- Universal-Image-Loader 基本使用
- 子级Repeater获取 父级Repeater
- mcstructs使用CMake生成Makefile文件
- MUI开发大全
- [爬虫]采用Go语言爬取天猫商品页面
- macOS 10.13 High Sierra odoo11 开发配置--完整版
- 全连接与softmax[转载]
- JQuery进度条
- Linux内存管理学习3 —— head.S中的段页表的建立
- Flutter学习之制作底部菜单导航
- Maven实战(九)---模块聚合和继承
热门文章
- CORS-跨域问题:Access-Control-Allow-Origin Header and the ASP.NET Web API
- Python | Pipenv官方推荐的python包管理工具
- DispatcherServlet 被加载顺序
- centos7.6环境编译安装php-7.2.24修复最新 CVE-2019-11043 漏洞
- [LeetCode] 359. Logger Rate Limiter 记录速率限制器
- jmap使用
- namespace Measure
- android基础---->;SharedPreferences的使用
- 第4/7Beta冲刺
- Windows网络命令的相关指令(1)