refactor: 删除冗余常量文件并整合常量定义
This commit is contained in:
35
src/framework/reqctx/param.go
Normal file
35
src/framework/reqctx/param.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package reqctx
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"be.ems/src/framework/ip2region"
|
||||
"be.ems/src/framework/utils/ua"
|
||||
)
|
||||
|
||||
// IPAddrLocation 解析ip地址
|
||||
func IPAddrLocation(c *gin.Context) (string, string) {
|
||||
ip := ip2region.ClientIP(c.ClientIP())
|
||||
location := "-" //ip2region.RealAddressByIp(ip)
|
||||
return ip, location
|
||||
}
|
||||
|
||||
// UaOsBrowser 解析请求用户代理信息
|
||||
func UaOsBrowser(c *gin.Context) (string, string) {
|
||||
userAgent := c.GetHeader("user-agent")
|
||||
uaInfo := ua.Info(userAgent)
|
||||
|
||||
browser := "-"
|
||||
if bName, bVersion := uaInfo.Browser(); bName != "" {
|
||||
browser = bName
|
||||
if bVersion != "" {
|
||||
browser = bName + " " + bVersion
|
||||
}
|
||||
}
|
||||
|
||||
os := "-"
|
||||
if bos := uaInfo.OS(); bos != "" {
|
||||
os = bos
|
||||
}
|
||||
return os, browser
|
||||
}
|
||||
Reference in New Issue
Block a user