× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Go - get parent struct

Simone Carletti
Mar 21, 2015
<p>You should retain a pointer to the hood.</p> <pre><code>type House struct { hood *Hood name string people int16 } </code></pre> <p>and when you append the house</p> <pre><code>func (h *Hood) addHouse(house House) []House { house.hood = h h.houses = append(h.houses, house) return h.houses } </code></pre> <p>then you can easily change the <code>GetHood</code>, although a getter may not be required at that point.</p> <pre><code>func (house *House) GetHood() Hood { return *house.hood } </code></pre> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/27918208/Go%20-%20get%20parent%20struct/27918316">Stack Overflow</a>.</p>
comments powered by Disqus