Пример #1
0
func libImportPath(typ, prefix string) (string, string) {
	// library use '.'
	if strings.Index(typ, ".") < 0 {
		return prefix + typ, prefix + typ
	}

	splitted := strings.Split(typ, ".")
	if len(splitted) != 2 {
		log.Fatalf("pythonLibImportPath invalid typ:" + typ)
	}
	// library name in the current document
	libName := splitted[0]

	// raml file of this lib
	libRAMLFile := globAPIDef.FindLibFile(commons.DenormalizePkgName(libName))

	if libRAMLFile == "" {
		log.Fatalf("pythonLibImportPath() can't find library : %v", libName)
	}

	// relative lib package
	libPkg := libRelDir(libRAMLFile)

	return strings.Replace(commons.NormalizePkgName(libPkg), "/", ".", -1) + "." + prefix + splitted[1], prefix + splitted[1]
}
Пример #2
0
// get library import path from a type
func libImportPath(rootImportPath, typ string) string {
	// library use '.', return nothing if it is not a library
	if strings.Index(typ, ".") < 0 {
		return ""
	}

	// library name in the current document
	libName := strings.Split(typ, ".")[0]

	if libName == "goraml" { // special package name, reserved for goraml
		return filepath.Join(rootImportPath, "goraml")
	}

	// raml file of this lib
	libRAMLFile := globAPIDef.FindLibFile(commons.DenormalizePkgName(libName))

	if libRAMLFile == "" {
		log.Fatalf("can't find library : %v", libName)
	}

	return filepath.Join(rootImportPath, goLibPackageDir(libName, libRAMLFile))
}