From e0a5698af99da4f42f4af38df69889da490c938a Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Tue, 28 Aug 2018 22:30:41 -0400 Subject: [PATCH] Add IsNil() method. --- cid.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cid.go b/cid.go index 786dbf9..cf7fcc6 100644 --- a/cid.go +++ b/cid.go @@ -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) {