当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.IsAbsPath方法代码示例

本文整理汇总了Golang中go/build.Context.IsAbsPath方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.IsAbsPath方法的具体用法?Golang Context.IsAbsPath怎么用?Golang Context.IsAbsPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在go/build.Context的用法示例。


在下文中一共展示了Context.IsAbsPath方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
	}
}
开发者ID:alexsaveliev,项目名称:vcsstore,代码行数:28,代码来源:buildfs.go

示例2: setMemoryContext

func (w *Walker) setMemoryContext(ctxt *build.Context) {
	ctxt.JoinPath = path.Join
	ctxt.IsAbsPath = path.IsAbs
	ctxt.IsDir = func(path string) bool { panic("unexpected") }
	ctxt.HasSubdir = func(root, dir string) (rel string, ok bool) { panic("unexpected") }
	ctxt.ReadDir = func(dir string) (fi []os.FileInfo, err error) { return w.readDir(dir) }
	ctxt.OpenFile = func(path string) (r io.ReadCloser, err error) { return w.openFile(path) }
}
开发者ID:John-Appleseed,项目名称:gowalker,代码行数:8,代码来源:walker.go

示例3: 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)
}
开发者ID:maddyonline,项目名称:gddo,代码行数:13,代码来源:build.go

示例4: IsAbsPath

// IsAbsPath behaves like filepath.IsAbs,
// but uses the build context's file system interface, if any.
func IsAbsPath(ctxt *build.Context, path string) bool {
	if ctxt.IsAbsPath != nil {
		return ctxt.IsAbsPath(path)
	}
	return filepath.IsAbs(path)
}
开发者ID:ColourboxDevelopment,项目名称:aws-sdk-go,代码行数:8,代码来源:util.go

示例5: setLocalContext

func (w *Walker) setLocalContext(ctxt *build.Context) {
	ctxt.IsAbsPath = path.IsAbs
}
开发者ID:John-Appleseed,项目名称:gowalker,代码行数:3,代码来源:walker.go


注:本文中的go/build.Context.IsAbsPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。