mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-03-22 02:51:50 +00:00
Web 服务
This commit is contained in:
36
pkg/mygin/mygin.go
Normal file
36
pkg/mygin/mygin.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package mygin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/p14yground/nezha/model"
|
||||
"github.com/p14yground/nezha/service/dao"
|
||||
)
|
||||
|
||||
// CommonEnvironment ..
|
||||
func CommonEnvironment(c *gin.Context, data map[string]interface{}) gin.H {
|
||||
data["MatchedPath"] = c.MustGet("MatchedPath")
|
||||
// 站点标题
|
||||
if t, has := data["Title"]; !has {
|
||||
data["Title"] = dao.Conf.Site.Brand
|
||||
} else {
|
||||
data["Title"] = fmt.Sprintf("%s - %s", t, dao.Conf.Site.Brand)
|
||||
}
|
||||
isLogin, ok := c.Get(model.CtxKeyIsUserLogin)
|
||||
if ok && isLogin.(bool) {
|
||||
data["Admin"] = dao.Admin
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
// RecordPath ..
|
||||
func RecordPath(c *gin.Context) {
|
||||
url := c.Request.URL.String()
|
||||
for _, p := range c.Params {
|
||||
url = strings.Replace(url, p.Value, ":"+p.Key, 1)
|
||||
}
|
||||
c.Set("MatchedPath", url)
|
||||
}
|
||||
Reference in New Issue
Block a user