Add IsNil() method.

This commit is contained in:
Kevin Atkinson
2018-08-28 22:30:41 -04:00
parent 667c6a9418
commit e0a5698af9

9
cid.go
View File

@@ -161,8 +161,17 @@ func NewCidV1(codecType uint64, mhash mh.Multihash) Cid {
// - hash mh.Multihash
type Cid struct{ str string }
// Nil can be used to represent a nil Cid, using Cid{} directly is
// also acceptable.
var Nil = Cid{}
// Nil returns true if a Cid is uninitialized or the Nil value.
// Calling any other methods on an uninitialized Cid will result in
// undefined behavior.
func (c Cid) IsNil() bool {
return c.str == ""
}
// Parse is a short-hand function to perform Decode, Cast etc... on
// a generic interface{} type.
func Parse(v interface{}) (Cid, error) {