本文整理汇总了Golang中go/build.Context.SplitPathList方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.SplitPathList方法的具体用法?Golang Context.SplitPathList怎么用?Golang Context.SplitPathList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/build.Context
的用法示例。
在下文中一共展示了Context.SplitPathList方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Setup
// Setup configures a *build.Context to use the given VFS
// as its filesystem.
func Setup(ctx *build.Context, fs vfs.VFS) {
ctx.JoinPath = path.Join
ctx.SplitPathList = filepath.SplitList
ctx.IsAbsPath = func(p string) bool {
return p != "" && p[0] == '/'
}
ctx.IsDir = func(p string) bool {
stat, err := fs.Stat(p)
return err == nil && stat.IsDir()
}
ctx.HasSubdir = func(root, dir string) (string, bool) {
root = path.Clean(root)
if !strings.HasSuffix(root, separator) {
root += separator
}
dir = path.Clean(dir)
if !strings.HasPrefix(dir, root) {
return "", false
}
return dir[len(root):], true
}
ctx.ReadDir = fs.ReadDir
ctx.OpenFile = func(p string) (io.ReadCloser, error) {
return fs.Open(p)
}
}
示例2: Import
// Import returns details about the package in the directory.
func (dir *Directory) Import(ctx *build.Context, mode build.ImportMode) (*build.Package, error) {
safeCopy := *ctx
ctx = &safeCopy
ctx.JoinPath = path.Join
ctx.IsAbsPath = path.IsAbs
ctx.SplitPathList = func(list string) []string { return strings.Split(list, ":") }
ctx.IsDir = func(path string) bool { return false }
ctx.HasSubdir = func(root, dir string) (rel string, ok bool) { return "", false }
ctx.ReadDir = dir.readDir
ctx.OpenFile = dir.openFile
return ctx.ImportDir(".", mode)
}
示例3: SplitPathList
// SplitPathList behaves like filepath.SplitList,
// but uses the build context's file system interface, if any.
func SplitPathList(ctxt *build.Context, s string) []string {
if ctxt.SplitPathList != nil {
return ctxt.SplitPathList(s)
}
return filepath.SplitList(s)
}