func printDir(path string) { if *local != "" { gosrc.SetLocalDevMode(*local) } dir, err := gosrc.Get(http.DefaultClient, path, *etag) if e, ok := err.(gosrc.NotFoundError); ok && e.Redirect != "" { log.Fatalf("redirect to %s", e.Redirect) } else if err != nil { log.Fatalf("%+v", err) } fmt.Println("ImportPath ", dir.ImportPath) fmt.Println("ResovledPath ", dir.ResolvedPath) fmt.Println("ProjectRoot ", dir.ProjectRoot) fmt.Println("ProjectName ", dir.ProjectName) fmt.Println("ProjectURL ", dir.ProjectURL) fmt.Println("VCS ", dir.VCS) fmt.Println("Etag ", dir.Etag) fmt.Println("BrowseURL ", dir.BrowseURL) fmt.Println("Subdirectories", strings.Join(dir.Subdirectories, ", ")) fmt.Println("LineFmt ", dir.LineFmt) fmt.Println("Files:") for _, file := range dir.Files { fmt.Printf("%30s %5d %s\n", file.Name, len(file.Data), file.BrowseURL) } }
func main() { flag.Parse() if len(flag.Args()) != 1 { log.Fatal("Usage: go run print.go importPath") } path := flag.Args()[0] var ( pdoc *doc.Package err error ) if *local { gosrc.SetLocalDevMode(os.Getenv("GOPATH")) } pdoc, err = doc.Get(http.DefaultClient, path, *etag) //} if err != nil { log.Fatal(err) } spew.Dump(pdoc) }