Is there a way to compare a struct with a slice field with the zero value struct?
<p>I have a <code>Favorites</code> struct with a slice field:</p>

<pre><code>type Favorites struct {
    Color string
    Lunch string
    Place string
    Hobbies []string 
}
</code></pre>

<p>and I have a <code>Person</code> which contains the other struct:</p>

<pre><code>type Person struct {
    Name string
    Favorites Favorites
}
</code></pre>

<p>I'd like to see if the <code>Favorites</code> field is set on Person.   For other types of fields, for example, a string or an int, I would compare that field to the zero value ("" or 0 respectively).</p>

<p>If I try to compare with the zero as below I get the error <code>invalid operation: p2.Favorites == zeroValue (struct containing []string cannot be compared)</code>:</p>

<pre><code>p2 := Person{Name: "Joe"}

zeroValue := Favorites{}
if p2.Favorites == zeroValue {
    fmt.Println("Favorites not set")
}
</code></pre>

<p>This matches what is defined in the spec (<a href="https://golang.org/ref/spec#Comparison_operators" rel="nofollow noreferrer">https://golang.org/ref/spec#Comparison_operators</a>).</p>

<p>Is there anyway to do this comparison other than tediously comparing every single field (and having to remember to update it if the struct changes)?</p>

<p>One option is to make the Favorites field a pointer to the struct instead of the struct itself and then just compare with nil, but this is in a large codebase so I'd rather not make potentially far-reaching changes in this case.</p>

<p><a href="https://play.golang.org/p/d0NSp8eBes" rel="nofollow noreferrer">https://play.golang.org/p/d0NSp8eBes</a></p>