Merge pull request #14595 from hakman/generics_add_alternatives

Add generics alternatives for fi.Bool/Float*/Int*/String*()
This commit is contained in:
Kubernetes Prow Robot 2022-11-18 13:38:40 -08:00 committed by GitHub
commit 7fe820e96d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

View File

@ -23,6 +23,19 @@ import (
"strconv"
)
// PtrTo returns a pointer to a copy of any value.
func PtrTo[T any](v T) *T {
return &v
}
// ValueOf returns the value of a pointer or its zero value
func ValueOf[T any](v *T) T {
if v == nil {
return *new(T)
}
return *v
}
func StringValue(s *string) string {
if s == nil {
return ""