Skip to content

Commit

Permalink
v0.0.3 - 更新security解析
Browse files Browse the repository at this point in the history
  • Loading branch information
spiritLHLS committed Jun 25, 2024
1 parent f9fbd60 commit bdb34d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions network/utils/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/oneclickvirt/basics/model"
)

// chooseString 用于选择非空字符串
func chooseString(src, dst string) string {
if src != "" {
Expand All @@ -14,7 +13,7 @@ func chooseString(src, dst string) string {
return dst
}

// CompareAndMergeIpInfo 用于比较和合并两个 IpInfo 结构体
// CompareAndMergeIpInfo 用于比较和合并两个 IpInfo 结构体,非空则不替换
func CompareAndMergeIpInfo(dst, src *model.IpInfo) (res *model.IpInfo, err error) {
if src == nil {
return nil, fmt.Errorf("Error merge IpInfo")
Expand All @@ -31,7 +30,7 @@ func CompareAndMergeIpInfo(dst, src *model.IpInfo) (res *model.IpInfo, err error
return dst, nil
}

// CompareAndMergeSecurityInfo 用于比较和合并两个 SecurityInfo 结构体
// CompareAndMergeSecurityInfo 用于比较和合并两个 SecurityInfo 结构体,非空则不替换
func CompareAndMergeSecurityInfo(dst, src *model.SecurityInfo) (res *model.SecurityInfo, err error) {
if src == nil {
return nil, fmt.Errorf("Error merge SecurityInfo")
Expand All @@ -50,5 +49,6 @@ func CompareAndMergeSecurityInfo(dst, src *model.SecurityInfo) (res *model.Secur
dst.IsVpn = chooseString(src.IsVpn, dst.IsVpn)
dst.IsAnonymous = chooseString(src.IsAnonymous, dst.IsAnonymous)
dst.IsThreat = chooseString(src.IsThreat, dst.IsThreat)
dst.Tag = "D"
return dst, nil
}
25 changes: 13 additions & 12 deletions network/utils/parse.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package utils

import (
"github.com/oneclickvirt/basics/model"
"strconv"
"strings"

"github.com/oneclickvirt/basics/model"
)

func ParseIpInfo(data map[string]interface{}) *model.IpInfo {
Expand Down Expand Up @@ -41,37 +42,37 @@ func ParseSecurityInfo(data map[string]interface{}) *model.SecurityInfo {
securityInfo := &model.SecurityInfo{}
if security, ok := data["security"].(map[string]interface{}); ok {
if isAbuser, ok := security["is_abuser"].(bool); ok {
securityInfo.IsAbuser = strconv.FormatBool(isAbuser)
securityInfo.IsAbuser = BoolToString(isAbuser)
}
if isAttacker, ok := security["is_attacker"].(bool); ok {
securityInfo.IsAttacker = strconv.FormatBool(isAttacker)
securityInfo.IsAttacker = BoolToString(isAttacker)
}
if isBogon, ok := security["is_bogon"].(bool); ok {
securityInfo.IsBogon = strconv.FormatBool(isBogon)
securityInfo.IsBogon = BoolToString(isBogon)
}
if isCloudProvider, ok := security["is_cloud_provider"].(bool); ok {
securityInfo.IsCloudProvider = strconv.FormatBool(isCloudProvider)
securityInfo.IsCloudProvider = BoolToString(isCloudProvider)
}
if isProxy, ok := security["is_proxy"].(bool); ok {
securityInfo.IsProxy = strconv.FormatBool(isProxy)
securityInfo.IsProxy = BoolToString(isProxy)
}
if isRelay, ok := security["is_relay"].(bool); ok {
securityInfo.IsRelay = strconv.FormatBool(isRelay)
securityInfo.IsRelay = BoolToString(isRelay)
}
if isTor, ok := security["is_tor"].(bool); ok {
securityInfo.IsTor = strconv.FormatBool(isTor)
securityInfo.IsTor = BoolToString(isTor)
}
if isTorExit, ok := security["is_tor_exit"].(bool); ok {
securityInfo.IsTorExit = strconv.FormatBool(isTorExit)
securityInfo.IsTorExit = BoolToString(isTorExit)
}
if isVpn, ok := security["is_vpn"].(bool); ok {
securityInfo.IsVpn = strconv.FormatBool(isVpn)
securityInfo.IsVpn = BoolToString(isVpn)
}
if isAnonymous, ok := security["is_anonymous"].(bool); ok {
securityInfo.IsAnonymous = strconv.FormatBool(isAnonymous)
securityInfo.IsAnonymous = BoolToString(isAnonymous)
}
if isThreat, ok := security["is_threat"].(bool); ok {
securityInfo.IsThreat = strconv.FormatBool(isThreat)
securityInfo.IsThreat = BoolToString(isThreat)
}
}
return securityInfo
Expand Down

0 comments on commit bdb34d0

Please sign in to comment.