iamjinlei / memfs

MemFS that implements http.FileSystem and http.File interface

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

MemFS

MemFS that implements http.FileSystem and http.File interface for quick mock up an in-memory http server

fs, _ := memfs.New(map[string][]byte{
	"/root/home/foo/1.txt": []byte("@/root/home/foo/1.txt"),
	"/root/home/bar/1.txt": []byte("@/root/home/bar/1.txt"),
	"/root/home/1.txt":     []byte("@/root/home/1.txt"),
	"/root/home/xyz/":      nil,
}, nil)

srv := &http.Server{Addr: ":8080"}
http.Handle("/", http.StripPrefix("/", http.FileServer(fs)))
srv.ListenAndServe()

Check the example folder for a working implementation

go run example/fileserver.go

About

MemFS that implements http.FileSystem and http.File interface

License:MIT License


Languages

Language:Go 100.0%