• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang vfs.NameSpace类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang vfs.ReadSeekCloser类代码示例发布时间:2022-05-28
下一篇:
Golang vfs.FileSystem类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap