Skip to content

Commit

Permalink
feat(helper): add ToValue generic function
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Dec 1, 2023
1 parent d29ffa8 commit ca9f0db
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fastly/basictypes_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ func ToPointer[T ~string | ~int | int32 | ~int64 | uint | uint8 | uint32 | ~bool
return &v
}

// ToValue converts *T to T.
// If not able to dereference, the zero value for the type is returned.
func ToValue[T ~string | ~int | int32 | ~int64 | uint | uint8 | uint32 | ~bool](v *T) T {
if v != nil {
return *v
}
var zero T
return zero
}

// NullString is a helper that returns a pointer to the string value passed in
// or nil if the string is empty.
//
Expand Down

0 comments on commit ca9f0db

Please sign in to comment.