title: How to get directory total size?
body: <p>So I am trying to get total size of a directory using Go. So far I have this:</p>
  
  <pre><code>var dirSize int64 = 0
  
  func readSize(path string, file os.FileInfo, err error) error {
      if !file.IsDir() {
          dirSize += file.Size()
      }
      return nil
  } 
  
  func DirSizeMB(path string) float64 {
      dirSize = 0
      filepath.Walk(path, readSize)
      sizeMB := float64(dirSize) / 1024.0 / 1024.0
      sizeMB = Round(sizeMB, .5, 2)
      return sizeMB
  }
  </code></pre>
  
  <p>The question is whether the <code>dirSize</code> global variable is going to cause problems and if it does, how do I move it to the scope of the <code>DirSizeMB</code> function?</p>