title: Relationship between a package statement and the directory of a .go file
body: <p>See this experiment.</p>
  
  <pre><code>~/go/src$ tree -F
  .
  ├── 1-foodir/
  │   └── 2-foofile.go
  └── demo.go
  
  1 directory, 2 files
  
  ~/go/src$ cat demo.go 
  package main
  
  import (
      "fmt"
      "1-foodir"
  )
  
  func main() {
      fmt.Println(foopkg.FooFunc())
  }
  
  ~/go/src$ cat 1-foodir/2-foofile.go 
  package foopkg
  
  func FooFunc() string {
      return "FooFunc"
  }
  
  ~/go/src$ GOPATH=~/go go run demo.go 
  FooFunc
  </code></pre>
  
  <p>I thought that we always import a package name. But the above example
  shows that we actually import a package directory name (<code>"1-foodir"</code>)
  but while invoking exported names within that package, we use the
  package name declared in the Go files (<code>foopkg.FooFunc</code>).</p>
  
  <p>This is confusing for a beginner like me who comes from Java and Python world,
  where the directory name itself is the package name used to qualify
  modules/classes defined in the package.</p>
  
  <p>Why is there a difference in the way we use <code>import</code> statement and
  refer to names defined in the package in Go? Can you explain the rules
  behind these things about Go?</p>