title: var vs := in Go
body: <p>In the Go web server example here: <a href="http://golang.org/doc/effective_go.html#web_server" rel="noreferrer">http://golang.org/doc/effective_go.html#web_server</a></p>
  
  <p>The following line of code works</p>
  
  <pre><code>var addr = flag.String("addr", ":1718", "http service address")
  </code></pre>
  
  <p>but changing it to</p>
  
  <pre><code>addr := flag.String("addr", ":1718", "http service address")
  </code></pre>
  
  <p>is a compilation error. Why? Does it have anything to do with the face that the return type of the function is <code>*string</code> instead of <code>string</code>? What difference does that make?</p>
  
  <p><strong>UPDATE</strong>: Thanks for pointing out that <code>:=</code> is not allowed at the top level. Any idea why this inconsistency is in the spec? I don't see any reason for the behaviour to be different inside a block.</p>