From bdb34d088d2cd438811f6e93d720ae72eacd8680 Mon Sep 17 00:00:00 2001 From: spiritlhl <103393591+spiritLHLS@users.noreply.github.com> Date: Tue, 25 Jun 2024 07:51:21 +0000 Subject: [PATCH] =?UTF-8?q?v0.0.3=20-=20=E6=9B=B4=E6=96=B0security?= =?UTF-8?q?=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- network/utils/merge.go | 6 +++--- network/utils/parse.go | 25 +++++++++++++------------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/network/utils/merge.go b/network/utils/merge.go index 9a780bc..b401c2e 100644 --- a/network/utils/merge.go +++ b/network/utils/merge.go @@ -5,7 +5,6 @@ import ( "github.com/oneclickvirt/basics/model" ) - // chooseString 用于选择非空字符串 func chooseString(src, dst string) string { if src != "" { @@ -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") @@ -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") @@ -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 } diff --git a/network/utils/parse.go b/network/utils/parse.go index 17127a3..3f462f2 100644 --- a/network/utils/parse.go +++ b/network/utils/parse.go @@ -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 { @@ -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