當前位置: 首頁>>代碼示例>>Golang>>正文


Golang vfs.Filesystem類代碼示例

本文整理匯總了Golang中github.com/blang/vfs.Filesystem的典型用法代碼示例。如果您正苦於以下問題:Golang Filesystem類的具體用法?Golang Filesystem怎麽用?Golang Filesystem使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Filesystem類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: writeFile

func writeFile(fs vfs.Filesystem, name string, flags int, mode os.FileMode, b []byte) (int, error) {
	f, err := fs.OpenFile(name, flags, mode)
	if err != nil {
		return 0, err
	}
	return f.Write(b)
}
開發者ID:gernest,項目名稱:vfs,代碼行數:7,代碼來源:memfs_test.go

示例2: readFile

func readFile(fs vfs.Filesystem, name string) ([]byte, error) {
	f, err := fs.OpenFile(name, os.O_RDONLY, 0)
	if err != nil {
		return nil, err
	}
	return ioutil.ReadAll(f)
}
開發者ID:gernest,項目名稱:vfs,代碼行數:7,代碼來源:memfs_test.go

示例3: GetInputPath

func GetInputPath(fs vfs.Filesystem, env venv.Env) string {

	var fn string

	fn = env.Getenv("TF_STATE")
	if fn != "" {
		return fn
	}

	fn = env.Getenv("TI_TFSTATE")
	if fn != "" {
		return fn
	}

	fn = "terraform.tfstate"
	_, err := fs.Stat(fn)
	if err == nil {
		return fn
	}

	fn = ".terraform/terraform.tfstate"
	_, err = fs.Stat(fn)
	if err == nil {
		return fn
	}

	return ""
}
開發者ID:adammck,項目名稱:terraform-inventory,代碼行數:28,代碼來源:input.go

示例4: ExampleMyFilesystem

func ExampleMyFilesystem() {
	// Simply bootstrap your filesystem
	var fs vfs.Filesystem = MyFS()

	err := fs.Mkdir("/tmp", 0777)
	if err != nil {
		fatal("Error will be: Not implemented yet!")
	}
}
開發者ID:gernest,項目名稱:vfs,代碼行數:9,代碼來源:example_myfs.go

示例5: ExampleMyWrapper

func ExampleMyWrapper() {

	// Disable Mkdirs on the OS Filesystem
	var fs vfs.Filesystem = NoNewDirs(vfs.OS())

	err := fs.Mkdir("/tmp", 0777)
	if err != nil {
		fatal("Mkdir disabled!")
	}
}
開發者ID:gernest,項目名稱:vfs,代碼行數:10,代碼來源:example_mywrapper.go

示例6: ExampleOsFS_myWrapper

func ExampleOsFS_myWrapper() {

	// Disable Mkdirs on the OS Filesystem
	var fs vfs.Filesystem = NoNewDirs(vfs.OS())

	err := fs.Mkdir("/tmp", 0777)
	if err != nil {
		fmt.Printf("Mkdir disabled!\n")
	}
}
開發者ID:blang,項目名稱:vfs,代碼行數:10,代碼來源:example_wrapping_test.go

示例7: writeFile

// port of ioutil.Writefile for vfs
func writeFile(fs vfs.Filesystem, filename string, data []byte, perm os.FileMode) error {
	f, err := fs.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
	if err != nil {
		return err
	}
	n, err := f.Write(data)
	if err == nil && n < len(data) {
		err = io.ErrShortWrite
	}
	if err1 := f.Close(); err == nil {
		err = err1
	}
	return err
}
開發者ID:adammck,項目名稱:terraform-inventory,代碼行數:15,代碼來源:input_test.go

示例8: ExampleDummyFS

func ExampleDummyFS() {
	// Simply bootstrap your filesystem
	var fs vfs.Filesystem = MyFS()

	// Your mkdir implementation
	fs.Mkdir("/tmp", 0777)

	// All necessary methods like OpenFile (therefor Create) are stubbed
	// and return the dummys error
	_, err := vfs.Create(fs, "/tmp/vfs/example.txt")
	if err != nil {
		fmt.Printf("Error will be: Not implemented yet!\n")
	}

}
開發者ID:blang,項目名稱:vfs,代碼行數:15,代碼來源:example_dummy_test.go

示例9: Example

func Example() {
	// Create a vfs accessing the filesystem of the underlying OS
	var osfs vfs.Filesystem = vfs.OS()
	osfs.Mkdir("/tmp", 0777)

	// Make the filesystem read-only:
	osfs = vfs.ReadOnly(osfs) // Simply wrap filesystems to change its behaviour

	// os.O_CREATE will fail and return vfs.ErrReadOnly
	// os.O_RDWR is supported but Write(..) on the file is disabled
	f, _ := osfs.OpenFile("/tmp/example.txt", os.O_RDWR, 0)

	// Return vfs.ErrReadOnly
	_, err := f.Write([]byte("Write on readonly fs?"))
	if err != nil {
		fmt.Errorf("Filesystem is read only!\n")
	}

	// Create a fully writable filesystem in memory
	mfs := memfs.Create()
	mfs.Mkdir("/root", 0777)

	// Create a vfs supporting mounts
	// The root fs is accessing the filesystem of the underlying OS
	fs := mountfs.Create(osfs)

	// Mount a memfs inside /memfs
	// /memfs may not exist
	fs.Mount(mfs, "/memfs")

	// This will create /testdir inside the memfs
	fs.Mkdir("/memfs/testdir", 0777)

	// This would create /tmp/testdir inside your OS fs
	// But the rootfs `osfs` is read-only
	fs.Mkdir("/tmp/testdir", 0777)
}
開發者ID:blang,項目名稱:vfs,代碼行數:37,代碼來源:example_test.go

示例10: listCollect

func listCollect(fs vfs.Filesystem, realPath, virtualPath string, filter FilterFile) ([]string, error) {
	files := []string{}
	contents, err := fs.ReadDir(realPath)
	if err != nil {
		return nil, err
	}
	sort.Sort(byName(contents))
	for _, content := range contents {
		if content.IsDir() {
			if filter(virtualPath+content.Name(), true) {
				subfiles, err := listCollect(fs, realPath+content.Name()+"/", virtualPath+content.Name()+"/", filter)
				if err != nil {
					return nil, err
				}
				files = append(files, subfiles...)
			}
		} else {
			if filter(virtualPath+content.Name(), false) {
				files = append(files, virtualPath+content.Name())
			}
		}
	}
	return files, nil
}
開發者ID:jwiklund,項目名稱:tmpl,代碼行數:24,代碼來源:io.go

示例11: TestInterface

func TestInterface(t *testing.T) {
	var fs vfs.Filesystem
	fs = Create()
	fs.Mkdir("/tmp", 0777)
}
開發者ID:gernest,項目名稱:vfs,代碼行數:5,代碼來源:memfs_test.go


注:本文中的github.com/blang/vfs.Filesystem類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。