title: How do I use reflect.DeepEqual() to compare a pointer's value against the zero value of its type?
body: <p>I need a generic function to check whether something is equal to its zero-value or not.</p>
  
  <p>From this <a href="https://stackoverflow.com/questions/13901819/quick-way-to-detect-empty-values-via-reflection-in-go">question</a>, I was able to find a function that worked with value types. I modified it to support pointers:</p>
  
  <pre><code>func isZeroOfUnderlyingType(x interface{}) bool {
  
      rawType := reflect.TypeOf(x)
  
      //source is a pointer, convert to its value
      if rawType.Kind() == reflect.Ptr {
          rawType = rawType.Elem()
      }
  
      return reflect.DeepEqual(x, reflect.Zero(rawType).Interface())
  }
  </code></pre>
  
  <p>Unfotunately, this didn't work for me when doing something like this:</p>
  
  <pre><code>type myStruct struct{}
  
  isZeroOfUnderlyingType(myStruct{}) //Returns true (works)
  
  isZeroOfUnderlyingType(&amp;myStruct{}) //Returns false (doesn't) work
  </code></pre>
  
  <p>This is because <code>&amp;myStruct{}</code> is a pointer and there is no way to dereference an <code>interface{}</code> inside the function. How do I compare the value of that pointer against the zero-value of its type?</p>