title: How to make nested object oriented function calls in GO
body: <p>I'm trying to make my Go application more object oriented. Right now I have the following call:</p>
  
  <pre><code>groups.AllGroups = GrowGroupsArray(groups.AllGroups)
  </code></pre>
  
  <p>Which calls:</p>
  
  <pre><code>func GrowGroupsArray(g []Group) []Group {
      newSlice := make([]Group, len(g), 2*cap(g)+1)
      copy(newSlice, g)
      g = newSlice
      return g
  }
  </code></pre>
  
  <p>This technically works but I would rather this:</p>
  
  <pre><code>//groups is of type Groups
  //AllGroups is of type []Group
  groups.AllGroups.GrowGroupsArray()
  
  func (g Groups) GrowGroupsArray() {
      newSlice := make([]Group, len(g), 2*cap(g)+1)
      copy(newSlice, g)
      g.AllGroups = newSlice
  }
  </code></pre>
  
  <p>This compiles fine but I get a runtime panic because nothing is being saved to the object when the function is completed (out of scope). I've encountered the exact same issue in several places where the first example works but the second will not save the new array to my object. The old array persists after the function has been called. Any help would be greatly appreciated. </p>