33 lines
881 B
Go
33 lines
881 B
Go
|
package utils
|
||
|
|
||
|
import (
|
||
|
"git.jmbit.de/jmb/patchman/client/common"
|
||
|
)
|
||
|
|
||
|
// DedupAndMergePackageList takes two slices of packages and inserts the values from List2 for Packages that are in both slices
|
||
|
func DedupAndMergePackageList(slice1 []common.ListPackage, slice2 []common.ListPackage) []common.ListPackage {
|
||
|
|
||
|
// Create a map to store structs by their names.
|
||
|
structMap := make(map[string]common.ListPackage)
|
||
|
|
||
|
// Function to process a slice and update the map.
|
||
|
processSlice := func(s []common.ListPackage) {
|
||
|
for _, item := range s {
|
||
|
structMap[item.Name] = item
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Write first Slice to map
|
||
|
processSlice(slice1)
|
||
|
|
||
|
// Write second slice to map
|
||
|
processSlice(slice2)
|
||
|
|
||
|
// Create a result slice based on the values from the map.
|
||
|
var resultSlice []common.ListPackage
|
||
|
for _, item := range structMap {
|
||
|
resultSlice = append(resultSlice, item)
|
||
|
}
|
||
|
return resultSlice
|
||
|
}
|