Files
query-orchestration/internal/validation/validation.go
T

42 lines
715 B
Go
Raw Normal View History

2025-01-23 14:56:20 +00:00
package validation
import "fmt"
func GetUpdatedValue[T any](def T, new *T) T {
if new != nil {
return *new
}
return def
}
func DeduplicateArray[T comparable](arr []T) []T {
occurred := make(map[T]bool)
result := []T{}
for _, value := range arr {
if !occurred[value] {
occurred[value] = true
result = append(result, value)
}
}
return result
}
func NormalizeInClosedInterval(updated **int32, current int32, min int32, max int32) error {
if updated == nil || *updated == nil {
return nil
}
if **updated == current {
*updated = nil
return nil
}
if **updated < min || **updated > max {
return fmt.Errorf("update must be in range: %d <= update <= %d", min, max)
}
return nil
}