GoDoxy/internal/utils/slices.go
Peter Olds 73de18e197
feat: add groups support for OIDC claims
Allow users to specify allowed groups in the env and use it to inspect the claims.

This performs a logical AND of users and groups (additive).
2025-01-13 21:40:10 -08:00

20 lines
489 B
Go

package utils
// Intersect returns a new slice containing the elements that are present in both input slices.
// This provides a more efficient solution than using two nested loops.
func Intersect[T comparable, Slice ~[]T](slice1 Slice, slice2 Slice) Slice {
var result Slice
seen := map[T]struct{}{}
for i := range slice1 {
seen[slice1[i]] = struct{}{}
}
for i := range slice2 {
if _, ok := seen[slice2[i]]; ok {
result = append(result, slice2[i])
}
}
return result
}