title: Go - package ast : find package in file
body: <p>I am parsing files with the <strong>ast package</strong>.<br>
  I have been looking at the documentation for a bit and I can't find a way to <strong>determine if a token is a package declaration</strong>, <em>e.g</em>: <code>package main</code> at the beggining of the file.</p>
  
  <pre><code>func find_package(node ast.Node) bool {
      switch x := node.(type) {
      // This works with *ast.Ident or *ast.FuncDecl ... but not
      // with *ast.Package
      case *ast.Package:
          fmt.Print(x.Name)
      }
      return true
  }
  </code></pre>
  
  <p>I am looking for a clean way to do this with the <strong>ast package</strong>, I am almost sure I am just missing something in the documentation.</p>