func main() { //PrintPackageSummary("gist.github.com/5639599.git"); return //PrintPackageSummariesInDir("gist.github.com") dpkg, err := gist5504644.GetDocPackageAll(gist5504644.BuildPackageFromImportPath("github.com/microcosm-cc/bluemonday")) if err != nil { panic(err) } PrintPackageFullSummary(dpkg) }
func PrintPackageSummary(importPath string) { dpkg, err := gist5504644.GetDocPackage(gist5504644.BuildPackageFromImportPath(importPath)) if err != nil { return } if !hasAnyFuncs(dpkg) { return } printPackageSummary(dpkg) }
func PrintPackageSummaryWithPath(importPath, fullPath string) { dpkg, err := gist5504644.GetDocPackage(gist5504644.BuildPackageFromImportPath(importPath)) if err != nil { return } if !hasAnyFuncs(dpkg) { return } fmt.Println(filepath.Join(fullPath, dpkg.Filenames[0])) printPackageSummary(dpkg) }
// GetForcedUseRenamed generates an anonymous usage of a renamed imported package. // // E.g., `io/ioutil`, `RenamedPkg` -> `var _ = RenamedPkg.NopCloser`. func GetForcedUseRenamed(importPath, localPackageName string) string { dpkg, err := gist5504644.GetDocPackage(gist5504644.BuildPackageFromImportPath(importPath)) if err != nil { return fmt.Sprintf("Package %q not valid (doesn't exist or can't be built).", importPath) } // Uncomment only for testing purposes. //dpkg.Funcs = dpkg.Funcs[0:0] //dpkg.Vars = dpkg.Vars[0:0] //dpkg.Consts = dpkg.Consts[0:0] //dpkg.Types = dpkg.Types[0:0] prefix := "var _ = " var usage string if len(dpkg.Funcs) > 0 { usage = dpkg.Funcs[0].Name } else if len(dpkg.Vars) > 0 { usage = dpkg.Vars[0].Names[0] } else if len(dpkg.Consts) > 0 { usage = dpkg.Consts[0].Names[0] } else if len(dpkg.Types) > 0 { usage = dpkg.Types[0].Name prefix = "var _ " } else { return "Package doesn't have a single public func, var, const or type." } switch { case localPackageName == "": return prefix + dpkg.Name + "." + usage case localPackageName == ".": return prefix + usage default: return prefix + localPackageName + "." + usage } }
func GoPackageFromImportPath(importPath string) *GoPackage { bpkg, err := gist5504644.BuildPackageFromImportPath(importPath) return goPackageFromBuildPackage(bpkg, err) }