本文整理汇总了Golang中path/filepath.SplitList函数的典型用法代码示例。如果您正苦于以下问题:Golang SplitList函数的具体用法?Golang SplitList怎么用?Golang SplitList使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SplitList函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: makePaths
// Expand GOROOT and GOPATH with respect to some dirPath.
func makePaths(dirPath string) (paths []string) {
if strings.HasPrefix(dirPath, ".") {
cwd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
dirPath = filepath.Join(cwd, dirPath[1:])
for _, dir := range filepath.SplitList(build.Default.GOPATH) {
if dir != "" && strings.HasPrefix(cwd, dir) {
paths = append(paths, dirPath)
}
}
return
}
// TODO(jtsai): Can dirPath be an absolute path?
for _, dir := range filepath.SplitList(build.Default.GOPATH) {
if dir != "" {
paths = append(paths, path.Join(dir, "src", dirPath))
}
}
if dir := build.Default.GOROOT; dir != "" {
paths = append(paths, path.Join(dir, "src", dirPath))
}
return
}
示例2: init
func init() {
Home = os.Getenv("HOME")
if Home == "" {
u, err := user.Current()
if err == nil {
Home = u.HomeDir
} else {
Home = filepath.Join(os.TempDir(), os.Args[0])
}
}
DataHome = getenv("XDG_DATA_HOME", filepath.Join(Home, ".local/share"))
ConfigHome = getenv("XDG_CONFIG_HOME", filepath.Join(Home, ".config"))
CacheHome = getenv("XDG_CACHE_HOME", filepath.Join(Home, ".cache"))
RuntimeDir = getenv("XDG_RUNTIME_DIR", CacheHome)
DataDirs = filepath.SplitList(os.Getenv("XDG_DATA_DIRS"))
if len(DataDirs) == 0 {
DataDirs = []string{"/usr/local/share", "/usr/share"}
}
ConfigDirs = filepath.SplitList(os.Getenv("XDG_CONFIG_DIRS"))
if len(ConfigDirs) == 0 {
ConfigDirs = []string{"/etc/xdg"}
}
}
示例3: symlinkToGopath
func symlinkToGopath(toolchain string) (skip string, err error) {
gopath := os.Getenv("GOPATH")
if gopath == "" {
return "", fmt.Errorf("GOPATH not set")
}
srcDir := filepath.Join(filepath.SplitList(gopath)[0], "src")
gopathDir := filepath.Join(srcDir, toolchain)
srclibpathDir := filepath.Join(filepath.SplitList(srclib.Path)[0], toolchain)
if fi, err := os.Lstat(gopathDir); os.IsNotExist(err) {
log.Printf("mkdir -p %s", filepath.Dir(gopathDir))
if err := os.MkdirAll(filepath.Dir(gopathDir), 0700); err != nil {
return "", err
}
log.Printf("ln -s %s %s", srclibpathDir, gopathDir)
if err := os.Symlink(srclibpathDir, gopathDir); err != nil {
log.Printf("Symlink failed %s", err)
return "", err
}
} else if err != nil {
return "", err
} else if fi.Mode()&os.ModeSymlink == 0 {
return fmt.Sprintf("toolchain dir in GOPATH (%s) is not a symlink (assuming you intentionally cloned the toolchain repo to your GOPATH; not modifying it)", gopathDir), nil
}
log.Printf("Symlinked toolchain %s into your GOPATH at %s", toolchain, gopathDir)
return "", nil
}
示例4: mergeIntoPath
func mergeIntoPath(g *libkb.GlobalContext, p2 string) error {
svcPath := os.Getenv("PATH")
g.Log.Debug("mergeIntoPath: service path = %s", svcPath)
g.Log.Debug("mergeIntoPath: merge path = %s", p2)
pathenv := filepath.SplitList(svcPath)
pathset := make(map[string]bool)
for _, p := range pathenv {
pathset[p] = true
}
var clientAdditions []string
for _, dir := range filepath.SplitList(p2) {
if _, ok := pathset[dir]; ok {
continue
}
clientAdditions = append(clientAdditions, dir)
}
pathenv = append(pathenv, clientAdditions...)
combined := strings.Join(pathenv, string(os.PathListSeparator))
if combined == svcPath {
g.Log.Debug("No path changes needed")
return nil
}
g.Log.Debug("mergeIntoPath: merged path = %s", combined)
os.Setenv("PATH", combined)
return nil
}
示例5: symlinkToGopath
func symlinkToGopath(toolchain string) error {
gopath := os.Getenv("GOPATH")
if gopath == "" {
return fmt.Errorf("GOPATH not set")
}
srcDir := filepath.Join(filepath.SplitList(gopath)[0], "src")
gopathDir := filepath.Join(srcDir, toolchain)
srclibpathDir := filepath.Join(filepath.SplitList(srclib.Path)[0], toolchain)
if fi, err := os.Lstat(gopathDir); os.IsNotExist(err) {
log.Printf("mkdir -p %s", filepath.Dir(gopathDir))
if err := os.MkdirAll(filepath.Dir(gopathDir), 0700); err != nil {
return err
}
log.Printf("ln -s %s %s", srclibpathDir, gopathDir)
if err := os.Symlink(srclibpathDir, gopathDir); err != nil {
return err
}
} else if err != nil {
return err
} else if fi.Mode()&os.ModeSymlink == 0 {
// toolchain dir in GOPATH is not a symlink, so assume they
// intentionally cloned the toolchain repo into their GOPATH.
return nil
}
log.Printf("Symlinked toolchain %s into your GOPATH at %s", toolchain, gopathDir)
return nil
}
示例6: find_global_file
func find_global_file(imp string, env *gocode_env) (string, bool) {
// gocode synthetically generates the builtin package
// "unsafe", since the "unsafe.a" package doesn't really exist.
// Thus, when the user request for the package "unsafe" we
// would return synthetic global file that would be used
// just as a key name to find this synthetic package
if imp == "unsafe" {
return "unsafe", true
}
pkgfile := fmt.Sprintf("%s.a", imp)
// if lib-path is defined, use it
if g_config.LibPath != "" {
for _, p := range filepath.SplitList(g_config.LibPath) {
pkg_path := filepath.Join(p, pkgfile)
if file_exists(pkg_path) {
return pkg_path, true
}
}
}
pkgdir := fmt.Sprintf("%s_%s", env.GOOS, env.GOARCH)
pkgpath := filepath.Join("pkg", pkgdir, pkgfile)
if env.GOPATH != "" {
for _, p := range filepath.SplitList(env.GOPATH) {
gopath_pkg := filepath.Join(p, pkgpath)
if file_exists(gopath_pkg) {
return gopath_pkg, true
}
}
}
goroot_pkg := filepath.Join(env.GOROOT, pkgpath)
return goroot_pkg, file_exists(goroot_pkg)
}
示例7: TestParseCov
func TestParseCov(t *testing.T) {
if output, err := exec.Command("go", "get", "github.com/axw/gocov/gocov").CombinedOutput(); err != nil {
t.Log(string(output))
t.Fatal(err)
return
}
path := filepath.SplitList(os.Getenv("PATH"))
for _, gopath := range filepath.SplitList(os.Getenv("GOPATH")) {
path = append(path, filepath.Join(gopath, "bin"))
}
os.Setenv("PATH", strings.Join(path, string(filepath.ListSeparator)))
cmd := exec.Command("gocov", "test", "github.com/BenLubar/goveralls/goveralls-test")
cmd.Stderr = os.Stderr
cov, err := cmd.Output()
if err != nil {
t.Fatal(err)
return
}
wd, err := os.Getwd()
if err != nil {
t.Fatal(err)
return
}
files := ParseCov(cov, wd)
if err != nil {
t.Fatal(err)
return
}
expectedJson, err := ioutil.ReadFile("goveralls-test/expected.json")
if err != nil {
t.Fatal(err)
return
}
var expected []*File
err = json.Unmarshal(expectedJson, &expected)
if err != nil {
t.Fatal(err)
return
}
filesJson, _ := json.Marshal(files)
expectedJson, _ = json.Marshal(expected)
if !bytes.Equal(filesJson, expectedJson) {
t.Errorf("Actual: \t%q", filesJson)
t.Errorf("Expected:\t%q", expectedJson)
}
}
示例8: find_global_file
func find_global_file(imp string) (string, bool) {
// gocode synthetically generates the builtin package
// "unsafe", since the "unsafe.a" package doesn't really exist.
// Thus, when the user request for the package "unsafe" we
// would return synthetic global file that would be used
// just as a key name to find this synthetic package
if imp == "unsafe" {
return "unsafe", true
}
pkgfile := fmt.Sprintf("%s.a", imp)
// if lib-path is defined, use it
if g_config.LibPath != "" {
for _, p := range filepath.SplitList(g_config.LibPath) {
pkg_path := filepath.Join(p, pkgfile)
if file_exists(pkg_path) {
return pkg_path, true
}
}
}
// otherwise figure out the default lib-path
gopath := os.Getenv("GOPATH")
goroot := os.Getenv("GOROOT")
goarch := os.Getenv("GOARCH")
goos := os.Getenv("GOOS")
if goroot == "" {
goroot = runtime.GOROOT()
}
if goarch == "" {
goarch = runtime.GOARCH
}
if goos == "" {
goos = runtime.GOOS
}
pkgdir := fmt.Sprintf("%s_%s", goos, goarch)
pkgpath := filepath.Join("pkg", pkgdir, pkgfile)
if gopath != "" {
for _, p := range filepath.SplitList(gopath) {
gopath_pkg := filepath.Join(p, pkgpath)
if file_exists(gopath_pkg) {
return gopath_pkg, true
}
}
}
goroot_pkg := filepath.Join(goroot, pkgpath)
return goroot_pkg, file_exists(goroot_pkg)
}
示例9: apply
// apply applies the configuration.
func (c *srcfileConfig) apply() error {
var versionValid bool
for _, v := range validVersions {
if config.GOVERSION == v {
versionValid = true
goBinaryName = fmt.Sprintf("go%s", config.GOVERSION)
if config.GOVERSION != "" && config.GOROOT == "" {
// If GOROOT is empty, assign $GOROOT<version_num> to it.
newGOROOT := os.Getenv(fmt.Sprintf("GOROOT%s", strings.Replace(config.GOVERSION, ".", "", -1)))
if newGOROOT != "" {
config.GOROOTForCmd = newGOROOT
}
}
break
}
}
if !versionValid {
return fmt.Errorf("The version %s is not valid. Use one of the following: %v", config.GOVERSION, validVersions)
}
if config.GOROOT != "" {
// clean/absolutize all paths
config.GOROOT = filepath.Clean(config.GOROOT)
if !filepath.IsAbs(config.GOROOT) {
config.GOROOT = filepath.Join(cwd, config.GOROOT)
}
buildContext.GOROOT = c.GOROOT
loaderConfig.Build = &buildContext
}
if config.GOPATH != "" {
// clean/absolutize all paths
dirs := cleanDirs(filepath.SplitList(config.GOPATH))
config.GOPATH = strings.Join(dirs, string(filepath.ListSeparator))
dirs = append(dirs, filepath.SplitList(buildContext.GOPATH)...)
buildContext.GOPATH = strings.Join(uniq(dirs), string(filepath.ListSeparator))
loaderConfig.Build = &buildContext
}
config.VendorDirs = cleanDirs(config.VendorDirs)
if config.GOROOTForCmd == "" {
config.GOROOTForCmd = buildContext.GOROOT
}
return nil
}
示例10: defaultBinary
func defaultBinary() string {
gopath := filepath.SplitList(os.Getenv("GOPATH"))
if len(gopath) == 0 {
return ""
}
return gopath[0] + "/bin/linux_amd64/cockroach"
}
示例11: Which
func Which(call []string) error {
options := WhichOptions{}
flagSet := uggo.NewFlagSetDefault("which", "[-a] args", VERSION)
flagSet.BoolVar(&options.all, "a", false, "Print all matching executables in PATH, not just the first.")
err := flagSet.Parse(call[1:])
if err != nil {
println("Error parsing flags")
return err
}
if flagSet.ProcessHelpOrVersion() {
return nil
}
args := flagSet.Args()
path := os.Getenv("PATH")
if runtime.GOOS == "windows" {
path = ".;" + path
}
pl := filepath.SplitList(path)
for _, arg := range args {
checkPathParts(arg, pl, options)
/*
if err != nil {
return err
}*/
}
return nil
}
示例12: TestBindAndroid
func TestBindAndroid(t *testing.T) {
if os.Getenv("ANDROID_HOME") == "" {
t.Skip("ANDROID_HOME not found, skipping bind")
}
buf := new(bytes.Buffer)
defer func() {
xout = os.Stderr
buildN = false
buildX = false
}()
xout = buf
buildN = true
buildX = true
buildO = "asset.aar"
buildTarget = "android"
gopath = filepath.SplitList(os.Getenv("GOPATH"))[0]
if goos == "windows" {
os.Setenv("HOMEDRIVE", "C:")
}
cmdBind.flag.Parse([]string{"github.com/c-darwin/mobile/asset"})
err := runBind(cmdBind)
if err != nil {
t.Log(buf.String())
t.Fatal(err)
}
diff, err := diffOutput(buf.String(), bindAndroidTmpl)
if err != nil {
t.Fatalf("computing diff failed: %v", err)
}
if diff != "" {
t.Errorf("unexpected output:\n%s", diff)
}
}
示例13: TestAndroidBuild
func TestAndroidBuild(t *testing.T) {
buf := new(bytes.Buffer)
defer func() {
xout = os.Stderr
buildN = false
buildX = false
}()
xout = buf
buildN = true
buildX = true
buildO = "basic.apk"
buildTarget = "android"
gopath = filepath.ToSlash(filepath.SplitList(os.Getenv("GOPATH"))[0])
if goos == "windows" {
os.Setenv("HOMEDRIVE", "C:")
}
cmdBuild.flag.Parse([]string{"golang.org/x/mobile/example/basic"})
ctx.BuildTags = []string{"tag1"}
err := runBuild(cmdBuild)
if err != nil {
t.Log(buf.String())
t.Fatal(err)
}
diff, err := diffOutput(buf.String(), androidBuildTmpl)
if err != nil {
t.Fatalf("computing diff failed: %v", err)
}
if diff != "" {
t.Errorf("unexpected output:\n%s", diff)
}
}
示例14: LookPath
// LookPath searches for an executable binary named file
// in the directories named by the PATH environment variable.
// If file contains a slash, it is tried directly and the PATH is not consulted.
// The result may be an absolute path or a path relative to the current directory.
func LookPath(file string) (string, error) {
// NOTE(rsc): I wish we could use the Plan 9 behavior here
// (only bypass the path if file begins with / or ./ or ../)
// but that would not match all the Unix shells.
if strings.Contains(file, "/") {
err := findExecutable(file)
if err == nil {
return file, nil
}
return "", &Error{file, err}
}
path := os.Getenv("PATH")
for _, dir := range filepath.SplitList(path) {
if dir == "" {
// Unix shell semantics: path element "" means "."
dir = "."
}
path := filepath.Join(dir, file)
if err := findExecutable(path); err == nil {
return path, nil
}
}
return "", &Error{file, ErrNotFound}
}
示例15: main
func main() {
flag.BoolVar(&fake, "n", false, "If true, don't actually do anything")
flag.BoolVar(&verbose, "v", false, "Provide verbose output")
flag.Var(&ignorePrefixes, "ignore", "Package prefix to ignore. Can be given multiple times.")
flag.Parse()
gopaths := filepath.SplitList(os.Getenv("GOPATH"))
if len(gopaths) == 0 {
log.Fatal("GOPATH must be set")
}
pkgName := flag.Arg(0)
if pkgName == "" {
log.Fatal("need a package name")
}
dest := flag.Arg(1)
if dest == "" {
log.Fatal("need a destination path")
}
ignorePrefixes = append(ignorePrefixes, pkgName)
ignorePrefixes = append(ignorePrefixes, dest)
rewrites = make(map[string]string)
visited = make(map[string]bool)
err := vendorize(pkgName, chooseGOPATH(gopaths, dest), dest)
if err != nil {
log.Fatal(err)
}
}