示例#1
0
func TestDatasource(t *testing.T) {
	fs := memfs.Create()
	fs.Mkdir("/tmp", 0777)
	f, _ := vfs.Create(fs, "/tmp/foo.json")
	f.Write([]byte(`{"hello":"world"}`))

	sources := make(map[string]*Source)
	sources["foo"] = &Source{
		Alias: "foo",
		URL: &url.URL{
			Scheme: "file",
			Path:   "/tmp/foo.json",
		},
		Ext:  "json",
		Type: "application/json",
		FS:   fs,
	}
	data := &Data{
		Sources: sources,
	}
	expected := make(map[string]interface{})
	expected["hello"] = "world"
	actual := data.Datasource("foo")
	assert.Equal(t, expected["hello"], actual["hello"])
}
示例#2
0
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")
	}

}
示例#3
0
func springxdsink(w rest.ResponseWriter, r *rest.Request) {

	// to do... add logic to make sure that files stored properly,
	// we need to generate a unique file scheme.

	file, err := vfs.Create(osfs, "root/signal.json")

	if err != nil {
		log.Fatal(err)
	}

	defer file.Close()
	if _, err := file.Write([]byte("VFS working on your filesystem")); err != nil {
		log.Fatal(err)
	}

}
示例#4
0
func ExampleBasicOS() {

	// Create a vfs accessing the filesystem of the underlying OS
	osFS := vfs.OS()
	err := osFS.Mkdir("/tmp/vfs", 0777)
	if err != nil {
		fatal("Error creating directory: %s\n", err)
	}

	// Convenience method
	f, err := vfs.Create(osFS, "/tmp/vfs/example.txt")
	// f, err := osFS.OpenFile("/tmp/vfs/example.txt", os.O_CREATE|os.O_RDWR, 0666)
	if err != nil {
		fatal("Could not create file: %s\n", err)
	}
	defer f.Close()
	if _, err := f.Write([]byte("VFS working on your filesystem")); err != nil {
		fatal("Error writing to file: %s\n", err)
	}
}