Example #1
0
func ExampleMountFS() {
	// Create a vfs supporting mounts
	// The root fs is accessing the filesystem of the underlying OS
	fs := mountfs.Create(vfs.OS())

	// Mount a memfs inside
	fs.Mount(memfs.Create(), "/memfs")

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

	// This will create /tmp/testdir inside your OS fs
	fs.Mkdir("/tmp/testdir", 0777)
}
Example #2
0
func main() {

	///////////////////////////////////////////////////
	////	Here is where we create our API
	////	We build End Points
	////	Set routes
	////	Create functions that serve end points
	// 		ToDo add end point to retrieve files, to do add hypermedia for discoverable
	//		Ned to fix references to API framework, so forking doesn't cause any sillyness
	//		Fernando Zavala 2/9/2016
	///////////////////////////////////////////////////
	osfs.Mkdir("root", 0777)

	// now, let's create the in memory fs object
	mfs := memfs.Create()
	mfs.Mkdir("/root/", 0777)

	// create a vfs that supports mounts
	// add conditional check for memfs -- todo
	fs := mountfs.Create(osfs)
	fs.Mount(mfs, "/memfs")

	// create directory inside of the mem file store
	fs.Mkdir("/memfs/root", 0777)

	// added stats end point to find response time
	api := rest.NewApi()
	MWstats := &rest.StatusMiddleware{}
	api.Use(MWstats)
	api.Use(rest.DefaultDevStack...)
	router, err := rest.MakeRouter(
		rest.Get("API/.status", func(w rest.ResponseWriter, r *rest.Request) {
			w.WriteJson(MWstats.GetStatus())
		}),
		// Root is API, Integration is self explanatory, gives api more structure.
		rest.Post("API/Integration/springxdsink", springxdsink),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)
	log.Fatal(http.ListenAndServe(":8080", api.MakeHandler()))
}
Example #3
0
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)
}