Files
be.ems/src/framework/reqctx/param.go

36 lines
732 B
Go

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
}