title: Variable initialization & scope in Golang
body: <p>I am learning go lang and I came across below code </p>
  
  <pre><code>var kvstore = make(map[string][]byte)
  
  // this function instantiates the database
  func init_db() {
      kvstore = make(map[string][]byte)
  }
  
  // put inserts a new key value pair or updates the value for a
  // given key in the store
  func put(key string, value []byte) {
      kvstore[key] = value
  }
  
  // get fetches the value associated with the key
  func get(key string) []byte {
      v, _ := kvstore[key]
      return v
  }
  </code></pre>
  
  <p>I have 2 doubts:</p>
  
  <ol>
  <li><p>why is it required to initialize <code>kvstore</code> variable once globally and then once in <code>init_db</code> function?</p></li>
  <li><p>When someone calls <code>put/get</code> function from other module how is the state of kvstore maintained? (In 'C' we generally have to explicitly pass the data structure to the function but in this case put or get directly works on global kvstore variable)</p></li>
  </ol>