title: How do packages work in golang
body: <p>I was trying to understand how packages work in go better in terms of what golang actually enforces rather than what is usually done or considered good practice (we can talk about good practice later too, but I wish to understand go first).</p>
  
  <p>From <a href="http://golang.org/doc/effective_go.html#package-names">effective go</a> it says:</p>
  
  <blockquote>
    <p>"Another convention is that the package name is the base name of its source directory..."</p>
  </blockquote>
  
  <p>However, the description above doesn't seem to be forced by go or required. Thus, I was wondering, if I was allowed to have <strong>multiple</strong> files with <strong>different</strong> package declarations at the top in the <strong>same</strong> directory base. If I am allowed to have multiple package declaration in the same directory, how do I then import them and use each one separately in the same file? Basically, I guess one of the problem I have is due to the wording of some of the go tutorial/documentation. If it is by convention, then for me, its implied that it is <strong>NOT enforced by the language</strong>. Because for example, go programmers do NOT write the keyword <code>func</code> for a function by convention. We write <code>func</code> because otherwise go will yell at you and it will <strong>not compile</strong>. Thus, I wish to clarify this with the example bellow (and if possible change the documentation for go, because this is a big deal in my opinion, how can this be done?).</p>
  
  <p>For example say I have three file <code>A.go</code>, <code>B.go</code>, <code>C.go</code> that print a print function <code>Print()</code> that simply prints a,b,c respectively. They are all on the same base directory called maybe <code>base</code>. Then each has a different package declaration <code>package Apkg, package Bpkg, package Cpkg</code>. </p>
  
  <p>how would you then go and import them? Would something as follow work?</p>
  
  <pre><code>package main
  
  import(
      nameA "github.com/user_me/base/Apkg"
      nameB "github.com/user_me/base/Bpkg"
      nameC "github.com/user_me/base/Cpkg"
  )
  
  func main() {
      nameA.Print() \\prints a
      nameB.Print() \\prints b
      nameC.Print() \\prints c
  }
  </code></pre>
  
  <p>or maybe we don't even need to specify the name if the package statments are the top are already different:</p>
  
  <pre><code>package main
  
  import(
      "github.com/user_me/base"
  )
  
  func main() {
      Apkg.Print() \\prints a
      Bpkg.Print() \\prints b
      Cpkg.Print() \\prints c
  }
  </code></pre>
  
  <p>the printing file are:</p>
  
  <p>A.go: </p>
  
  <pre><code>//file at github.com.user_me/base and name A.go
  package Apkg
  
  import "fmt"
  
  func Print(){
      fmt.Println("A")
  }
  </code></pre>
  
  <p>B.go:</p>
  
  <pre><code>//file at github.com.user_me/base and name B.go
  package Bpkg
  
  import "fmt"
  
  func Print(){
      fmt.Println("B")
  }
  </code></pre>
  
  <p>C.go:
      //file at github.com.user_me/base and name C.go
      package Cpkg</p>
  
  <pre><code>import "fmt"
  
  func Print(){
      fmt.Println("C")
  }
  </code></pre>
  
  <p>Also, if you can have a name <strong>different</strong> from the <code>base</code>, could someone clarify to me how the import is actually done? If the package name is <code>package Apkg</code> in base does the import have to be <code>import github.com/user_me/base</code> or <code>import github.com/user_me/base/Apkg</code> or <code>github.com/user_me/Apkg</code>.</p>
  
  <p>I have not yet tested this but I will do so soon. The importing deal in go has been a little confusing for me and would love to get an answer and share it with the world.</p>