mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-03-22 19:40:08 +00:00
Co-authored-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> Co-authored-by: Elias Schneider <login@eliasschneider.com>
12 lines
214 B
Go
12 lines
214 B
Go
package utils
|
|
|
|
// 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
|
|
}
|