Ejemplo n.º 1
0
func PrintPackageSummary(importPath string) {
	dpkg, err := gist5504644.GetDocPackage(gist5504644.BuildPackageFromImportPath(importPath))
	if err != nil {
		return
	}
	if !hasAnyFuncs(dpkg) {
		return
	}
	printPackageSummary(dpkg)
}
Ejemplo n.º 2
0
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)
}
Ejemplo n.º 3
0
// 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
	}
}