本文整理汇总了Golang中golang.org/x/tools/godoc/vfs.NameSpace类的典型用法代码示例。如果您正苦于以下问题:Golang NameSpace类的具体用法?Golang NameSpace怎么用?Golang NameSpace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NameSpace类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestNewNameSpace
func TestNewNameSpace(t *testing.T) {
// We will mount this filesystem under /fs1
mount := mapfs.New(map[string]string{"fs1file": "abcdefgh"})
// Existing process. This should give error on Stat("/")
t1 := vfs.NameSpace{}
t1.Bind("/fs1", mount, "/", vfs.BindReplace)
// using NewNameSpace. This should work fine.
t2 := emptyvfs.NewNameSpace()
t2.Bind("/fs1", mount, "/", vfs.BindReplace)
testcases := map[string][]bool{
"/": []bool{false, true},
"/fs1": []bool{true, true},
"/fs1/fs1file": []bool{true, true},
}
fss := []vfs.FileSystem{t1, t2}
for j, fs := range fss {
for k, v := range testcases {
_, err := fs.Stat(k)
result := err == nil
if result != v[j] {
t.Errorf("fs: %d, testcase: %s, want: %v, got: %v, err: %s", j, k, v[j], result, err)
}
}
}
}
开发者ID:srinathh,项目名称:emptyvfs,代码行数:31,代码来源:emptyvfs_test.go
示例2: Union
// Union returns a new FileSystem which is the union of the provided file systems.
// For read operations, vfs.NameSpace is used and its behavior is inherited.
// Write operations are applied to the first file system which contains the parent directory.
// The union file system is not thread-safe. Concurrent access to itself and/or
// its underlying file systems requires synchronization.
func Union(fileSystems ...FileSystem) FileSystem {
if len(fileSystems) == 0 {
return ReadOnly(Map(nil))
}
if len(fileSystems) == 1 {
return fileSystems[0]
}
ns := vfs.NameSpace{}
for _, fs := range fileSystems {
ns.Bind("/", fs, "/", vfs.BindAfter)
}
return &unionFS{
NameSpace: ns,
fileSystems: fileSystems,
}
}
开发者ID:alexsaveliev,项目名称:rwvfs,代码行数:22,代码来源:union.go
示例3: paths
// paths determines the paths to use.
//
// If we are passed an operating system path like . or ./foo or /foo/bar or c:\mysrc,
// we need to map that path somewhere in the fs name space so that routines
// like getPageInfo will see it. We use the arbitrarily-chosen virtual path "/target"
// for this. That is, if we get passed a directory like the above, we map that
// directory so that getPageInfo sees it as /target.
// Returns the absolute and relative paths.
func paths(fs vfs.NameSpace, pres *Presentation, path string) (string, string) {
if filepath.IsAbs(path) {
fs.Bind(target, vfs.OS(path), "/", vfs.BindReplace)
return target, target
}
if build.IsLocalImport(path) {
cwd, _ := os.Getwd() // ignore errors
path = filepath.Join(cwd, path)
fs.Bind(target, vfs.OS(path), "/", vfs.BindReplace)
return target, target
}
if bp, _ := build.Import(path, "", build.FindOnly); bp.Dir != "" && bp.ImportPath != "" {
fs.Bind(target, vfs.OS(bp.Dir), "/", vfs.BindReplace)
return target, bp.ImportPath
}
return pathpkg.Join(pres.PkgFSRoot(), path), path
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:25,代码来源:cmdline.go
示例4: NewNameSpace
// NewNameSpace returns a vfs.NameSpace initialized with an empty
// emulated directory mounted on the root mount point "/" so that
// directory traversal routines don't break if the user doesn't
// explicitly mount a FileSystem at "/". See the following issue:
// https://github.com/golang/go/issues/14190
func NewNameSpace() vfs.NameSpace {
ns := vfs.NameSpace{}
ns.Bind("/", newemptyVFS(), "/", vfs.BindReplace)
return ns
}
开发者ID:srinathh,项目名称:emptyvfs,代码行数:10,代码来源:emptyvfs.go
示例5: fileExists
func (p *localTranslater) fileExists(fs vfs.NameSpace, name string) bool {
if fi, err := fs.Stat(name); err != nil || fi.IsDir() {
return false
}
return true
}
开发者ID:iolg,项目名称:golangdoc,代码行数:6,代码来源:local_translater.go
注:本文中的golang.org/x/tools/godoc/vfs.NameSpace类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论