go使用map去重
mapData := make(map[string]*csEntity.SyncCodeScanRecordSdkDtl) linq.From(sdkResult).ForEachT(func(sdk *csEntity.CodeScanRecordSDKDetailPo) { if len(sdk.SdkId) == 0 || len(sdk.SdkVersion) == 0 { log.ErrorContextf(ctx, "[syncSdkConfigLib]-sdkid[%d]或sdkversion[%d]不能为空", sdk.SdkId, sdk.SdkVersion) err = errors.New("[syncSdkConfigLib]-sdkid[%d]或sdkversion[%d]不能为空") } var leak []null.String var read []null.String if len(sdk.PrivacyLeakData.String) > 0 { leak = append(leak, sdk.PrivacyLeakData) } if len(sdk.PrivacyReadData.String) > 0 { read = append(read, sdk.PrivacyReadData) } if mapData[sdk.SdkId+"_"+sdk.SdkVersion] == nil { mapData[sdk.SdkId+"_"+sdk.SdkVersion] = &csEntity.SyncCodeScanRecordSdkDtl{ Category: sdk.Category, CorporateName: sdk.CompanyName, Description: sdk.Description, SdkId: sdk.SdkId, SdkName: sdk.ChineseName, Version: sdk.SdkVersion, SdkFunction: sdk.Capability, Website: sdk.Website, PrivacyDataLeak: leak, PrivacyDataRead: read, } } })
for _, val := range mapData {
codeScanSdkDtlList = append(codeScanSdkDtlList, val)
}