internal/pkg/default.go
package pkg
// GetDefault returns the value if it is not the zero value of the type, otherwise
// it returns the fallback.
func GetDefault[T comparable](value, fallback T) T {
var zero T
if value == zero {
return fallback
}
return value
}
// GetDefaultPtr returns the value if it is not nil, otherwise it returns the
// fallback.
func GetDefaultPtr[T any](value *T, fallback T) T {
if value == nil {
return fallback
}
return *value
}