You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

47 lines
914 B

package utilService
import (
"GoClouds/core/cloud/userCloud"
"GoClouds/models"
"fmt"
"github.com/gin-gonic/gin"
ruisUtil "github.com/mgr9525/go-ruisutil"
"net/http"
)
const LgUserKey = "mid-lguser"
func MidCheckUser(c *gin.Context) {
lguser := userCloud.CurrUser(c)
if lguser == nil {
c.String(403, "未登录")
c.Abort()
return
}
c.Set(LgUserKey, lguser)
c.Next()
}
func GetMidLgUser(c *gin.Context) *models.SysUser {
usr, ok := c.Get(LgUserKey)
if !ok {
return nil
}
lguser, ok := usr.(*models.SysUser)
if !ok {
return nil
}
return lguser
}
func MidNotFound404(c *gin.Context) {
c.Next()
if c.Writer.Status() == http.StatusNotFound && c.Writer.Size() <= 0 {
data := ruisUtil.Map{}
data["msg"] = "未找到页面!正在跳转。。。"
msg, ok := c.Get("404msg")
if ok {
data["msg"] = fmt.Sprintf("%v", msg)
}
c.HTML(http.StatusNotFound, "goto.html", data)
}
}