mirror of
https://github.com/oneclickvirt/basics.git
synced 2025-10-05 16:48:09 +08:00
55 lines
1.8 KiB
Go
55 lines
1.8 KiB
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
networkModel "github.com/oneclickvirt/basics/network/model"
|
|
)
|
|
|
|
// chooseString 用于选择非空字符串
|
|
func chooseString(src, dst string) string {
|
|
if src != "" {
|
|
return src
|
|
}
|
|
return dst
|
|
}
|
|
|
|
// CompareAndMergeIpInfo 用于比较和合并两个 IpInfo 结构体
|
|
func CompareAndMergeIpInfo(dst, src *networkModel.IpInfo) (res *networkModel.IpInfo, err error) {
|
|
if src == nil {
|
|
return nil, fmt.Errorf("Error merge IpInfo")
|
|
}
|
|
if dst == nil {
|
|
dst = &networkModel.IpInfo{}
|
|
}
|
|
dst.Ip = chooseString(src.Ip, dst.Ip)
|
|
dst.ASN = chooseString(src.ASN, dst.ASN)
|
|
dst.Org = chooseString(src.Org, dst.Org)
|
|
dst.Country = chooseString(src.Country, dst.Country)
|
|
dst.Region = chooseString(src.Region, dst.Region)
|
|
dst.City = chooseString(src.City, dst.City)
|
|
return dst, nil
|
|
}
|
|
|
|
// CompareAndMergeSecurityInfo 用于比较和合并两个 SecurityInfo 结构体
|
|
func CompareAndMergeSecurityInfo(dst, src *networkModel.SecurityInfo) (res *networkModel.SecurityInfo, err error) {
|
|
if src == nil {
|
|
return nil, fmt.Errorf("Error merge SecurityInfo")
|
|
}
|
|
if dst == nil {
|
|
dst = &networkModel.SecurityInfo{}
|
|
}
|
|
dst.IsAbuser = chooseString(src.IsAbuser, dst.IsAbuser)
|
|
dst.IsAttacker = chooseString(src.IsAttacker, dst.IsAttacker)
|
|
dst.IsBogon = chooseString(src.IsBogon, dst.IsBogon)
|
|
dst.IsCloudProvider = chooseString(src.IsCloudProvider, dst.IsCloudProvider)
|
|
dst.IsProxy = chooseString(src.IsProxy, dst.IsProxy)
|
|
dst.IsRelay = chooseString(src.IsRelay, dst.IsRelay)
|
|
dst.IsTor = chooseString(src.IsTor, dst.IsTor)
|
|
dst.IsTorExit = chooseString(src.IsTorExit, dst.IsTorExit)
|
|
dst.IsVpn = chooseString(src.IsVpn, dst.IsVpn)
|
|
dst.IsAnonymous = chooseString(src.IsAnonymous, dst.IsAnonymous)
|
|
dst.IsThreat = chooseString(src.IsThreat, dst.IsThreat)
|
|
return dst, nil
|
|
}
|