feat: UA和IP地址多语言
This commit is contained in:
@@ -82,13 +82,13 @@ func UaOsBrowser(c *gin.Context) (string, string) {
|
|||||||
userAgent := c.GetHeader("user-agent")
|
userAgent := c.GetHeader("user-agent")
|
||||||
uaInfo := ua.Info(userAgent)
|
uaInfo := ua.Info(userAgent)
|
||||||
|
|
||||||
browser := "Unknown Unknown"
|
browser := "app.common.noUaOsBrowser"
|
||||||
bName, bVersion := uaInfo.Browser()
|
bName, bVersion := uaInfo.Browser()
|
||||||
if bName != "" && bVersion != "" {
|
if bName != "" && bVersion != "" {
|
||||||
browser = bName + " " + bVersion
|
browser = bName + " " + bVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
os := "Unknown Unknown"
|
os := "app.common.noUaOsBrowser"
|
||||||
bos := uaInfo.OS()
|
bos := uaInfo.OS()
|
||||||
if bos != "" {
|
if bos != "" {
|
||||||
os = bos
|
os = bos
|
||||||
@@ -116,7 +116,8 @@ func LoginUser(c *gin.Context) (vo.LoginUser, error) {
|
|||||||
if exists {
|
if exists {
|
||||||
return value.(vo.LoginUser), nil
|
return value.(vo.LoginUser), nil
|
||||||
}
|
}
|
||||||
return vo.LoginUser{}, fmt.Errorf("invalid login user information")
|
// 登录用户信息无效
|
||||||
|
return vo.LoginUser{}, fmt.Errorf("app.common.noLoginUser")
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoginUserToUserID 登录用户信息-用户ID
|
// LoginUserToUserID 登录用户信息-用户ID
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func RegionSearchByIp(ip string) (string, int, int64) {
|
|||||||
ip = ClientIP(ip)
|
ip = ClientIP(ip)
|
||||||
if ip == LOCAT_HOST {
|
if ip == LOCAT_HOST {
|
||||||
// "0|0|0|内网IP|内网IP"
|
// "0|0|0|内网IP|内网IP"
|
||||||
return "0|0|0|Intranet IP|Intranet IP", 0, 0
|
return "0|0|0|app.common.noIPregion|app.common.noIPregion", 0, 0
|
||||||
}
|
}
|
||||||
tStart := time.Now()
|
tStart := time.Now()
|
||||||
region, err := searcher.SearchByStr(ip)
|
region, err := searcher.SearchByStr(ip)
|
||||||
@@ -60,19 +60,19 @@ func RegionSearchByIp(ip string) (string, int, int64) {
|
|||||||
func RealAddressByIp(ip string) string {
|
func RealAddressByIp(ip string) string {
|
||||||
ip = ClientIP(ip)
|
ip = ClientIP(ip)
|
||||||
if ip == LOCAT_HOST {
|
if ip == LOCAT_HOST {
|
||||||
return "Intranet IP" // 内网IP
|
return "app.common.noIPregion" // 内网IP
|
||||||
}
|
}
|
||||||
region, err := searcher.SearchByStr(ip)
|
region, err := searcher.SearchByStr(ip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("failed to SearchIP(%s): %s\n", ip, err)
|
logger.Errorf("failed to SearchIP(%s): %s\n", ip, err)
|
||||||
return "unknown" // 未知
|
return "app.common.unknown" // 未知
|
||||||
}
|
}
|
||||||
parts := strings.Split(region, "|")
|
parts := strings.Split(region, "|")
|
||||||
province := parts[2]
|
province := parts[2]
|
||||||
city := parts[3]
|
city := parts[3]
|
||||||
if province == "0" && city != "0" {
|
if province == "0" && city != "0" {
|
||||||
if city == "内网IP" {
|
if city == "内网IP" {
|
||||||
return "Intranet IP" // 内网IP
|
return "app.common.noIPregion" // 内网IP
|
||||||
}
|
}
|
||||||
return city
|
return city
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user