gofrs / uuid

A UUID package for Go
MIT License
1.57k stars 110 forks source link

consider adding IsZero() property #92

Closed kevinburke1 closed 2 years ago

kevinburke1 commented 3 years ago

Right now to tell if a UUID is entirely empty, you need to do this fairly clunky operation:

if bytes.Equal(myUUID[:], uuid.Nil[:]) {
    ...
}

It might be nice to add IsZero() - matching the API for time.Time - that will handle this for you.

theckman commented 3 years ago

@kevinburkemeter since they are an array type you can just compare them with ==. Any reason you can't do that here?

izolate commented 2 years ago

@theckman You can't always count on having access to the uuid package, for example within Go templates, it would be nice to do this:

{{if .SomeUUID.IsZero}}
Some UUID is nil
{{end}}

+1 for the suggestion to add an IsZero method.

cameracker commented 2 years ago

Thanks for the recommendation @kevinburke1 , this has been contributed by @jordan-chalupka in #95, and is out for release in v4.2.0.