1 Star 0 Fork 0

dabolau / umbrella

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
authName.go 576 Bytes
一键复制 编辑 原始数据 按行查看 历史
dabolau 提交于 2020-12-07 17:13 . 更新程序
package middleware
import (
"log"
"net/http"
"github.com/gin-gonic/gin"
)
// AuthName 验证姓名中间件
// https://gin-gonic.com/docs/examples/custom-middleware/
func AuthName() gin.HandlerFunc {
return func(c *gin.Context) {
log.Println("验证姓名中间件")
// 在请求上下文中获取值,需在中间件中设置
fullname := c.MustGet("fullname").(string)
log.Println(fullname)
if fullname == "" {
// 不调用该请求的剩余处理程序
c.Abort()
// 页面跳转
c.Redirect(http.StatusFound, "/user/profile")
return
}
}
}
Go
1
https://gitee.com/dabolau/umbrella.git
git@gitee.com:dabolau/umbrella.git
dabolau
umbrella
umbrella
34b391d33531

搜索帮助