title: How to make struct survive outside its Go routine when using pointers to external struct
body: <p>When I run this code with <code>go run main.go</code>, then I see this output:</p>
  
  <pre class="lang-sh prettyprint-override"><code>inner: {Bar:{Baz:xyz} BarPtr:0xc0000101e0}
  outer: {Bar:{Baz:} BarPtr:&lt;nil&gt;}
  </code></pre>
  
  <p>I can not understand why when passing a pointer to a routine, then the struct <strong>created</strong> inside that routine can not be exposed outside via pointers.</p>
  
  <p>I know I could use a channel to publish the structs created inside the Go routine, but the piece of code I am working on would require too much additional boilerplate code. I would like to use a Wait Group with pointers if possible, but I can not find a way so I am wondering if this is possible at all?</p>
  
  <p>To me I should be able to expose an internal struct via a pointer, but I am not sure maybe the compiler silently ignores this, or am I failing to understand some fundamental features of Go?</p>
  
  <pre class="lang-golang prettyprint-override"><code>package main
  
  import (
      "fmt"
      "sync"
  )
  
  type Foo struct {
      Bar    Bar
      BarPtr *Bar
  }
  
  type Bar struct {
      Baz string
  }
  
  func main() {
      foo := Foo{}
      var wg sync.WaitGroup
      // the real example has more routines, so I need a wait group
      wg.Add(1)
      go func(strct *Foo) {
          defer wg.Done()
          bar1 := Bar{
              Baz: "xyz",
          }
          bar2 := Bar{
              Baz: "abc",
          }
          ownFoo := Foo{
              Bar:    bar1,
              BarPtr: &amp;bar2,
          }
          fmt.Printf("inner: %+v\n", ownFoo)
          strct = &amp;ownFoo
      }(&amp;foo)
      wg.Wait()
      fmt.Printf("outer: %+v\n", foo)
  }
  </code></pre>