title: Initialize a variable over a function by reference in golang
body: <p>If I have a function which takes a reference as an argument and I want to use that function to initialize a variable I need to do this inside the init() function. That solution works, but it smells not really correct to me.</p>
  
  <p>Is there another way to initialize a variable for a package in go like to use the init() function?</p>
  
  <p>I think that there must be a better way. I thought already about a wrapping function, but that makes the logik not better.</p>
  
  <p>I prepared a short and simple example
      package main</p>
  
  <pre><code>import (
      "fmt"
  )
  
  var a string
  //A use of a function is not allowed
  //foo(&amp;a)
  
  
  //Need to call init
  func init() {
      foo(&amp;a)
  }
  
  func main() {
      fmt.Println(a)
  }
  
  func foo(b *string) {
      *b = "abc"
  }
  </code></pre>
  
  <p><a href="https://play.golang.org/p/GdBiDFB1KAe" rel="nofollow noreferrer">https://play.golang.org/p/GdBiDFB1KAe</a></p>