mirror of
https://github.com/datarhei/core.git
synced 2025-10-06 00:17:07 +08:00

This secret will be used to encrypt automatically obtained secrets at rest, i.e. in a storage. They will be decrypted on demand. If the secret is wrong, stored certificates can't be decrypted. For changing the secret, the stored certificated must be deleted first in order to obtain new ones that will be encrypted with the new secret.
29 lines
553 B
Go
29 lines
553 B
Go
package slices
|
|
|
|
// Diff returns a sliceof newly added entries and a slice of removed entries based
|
|
// the provided slices.
|
|
func Diff[T comparable](next, current []T) ([]T, []T) {
|
|
added, removed := []T{}, []T{}
|
|
|
|
currentMap := map[T]struct{}{}
|
|
|
|
for _, name := range current {
|
|
currentMap[name] = struct{}{}
|
|
}
|
|
|
|
for _, name := range next {
|
|
if _, ok := currentMap[name]; ok {
|
|
delete(currentMap, name)
|
|
continue
|
|
}
|
|
|
|
added = append(added, name)
|
|
}
|
|
|
|
for name := range currentMap {
|
|
removed = append(removed, name)
|
|
}
|
|
|
|
return added, removed
|
|
}
|