mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-14 01:03:02 +03:00
17 lines
299 B
Go
17 lines
299 B
Go
package utils
|
|
|
|
// Ptr returns a pointer to the given value.
|
|
func Ptr[T any](v T) *T {
|
|
return &v
|
|
}
|
|
|
|
// PtrOrNil returns a pointer to v if v is not the zero value of its type,
|
|
// otherwise it returns nil.
|
|
func PtrOrNil[T comparable](v T) *T {
|
|
var zero T
|
|
if v == zero {
|
|
return nil
|
|
}
|
|
return &v
|
|
}
|