vfs

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileServer

func FileServer(root http.FileSystem) http.Handler

FileServer returns a handler that serves HTTP requests with the contents of the file system rooted at root.

To use the operating system's file system implementation, use http.Dir:

http.Handle("/", http.FileServer(http.Dir("/tmp")))

As a special case, the returned file server redirects any request ending in "/index.html" to the same path, without the final "index.html".

func RegisterFS

func RegisterFS(fs http.FileSystem)

func ServeContent

func ServeContent(w http.ResponseWriter, req *http.Request, name string, modtime time.Time, content io.ReadSeeker)

ServeContent replies to the request using the content in the provided ReadSeeker. The main benefit of ServeContent over io.Copy is that it handles Range requests properly, sets the MIME type, and handles If-Match, If-Unmodified-Since, If-None-Match, If-Modified-Since, and If-Range requests.

If the response's Content-Type header is not set, ServeContent first tries to deduce the type from name's file extension and, if that fails, falls back to reading the first block of the content and passing it to DetectContentType. The name is otherwise unused; in particular it can be empty and is never sent in the response.

If modtime is not the zero time or Unix epoch, ServeContent includes it in a Last-Modified header in the response. If the request includes an If-Modified-Since header, ServeContent uses modtime to decide whether the content needs to be sent at all.

The content's Seek method must work: ServeContent uses a seek to the end of the content to determine its size.

If the caller has set w's ETag header formatted per RFC 7232, section 2.3, ServeContent uses it to handle requests using If-Match, If-None-Match, or If-Range.

Note that *os.File implements the io.ReadSeeker interface.

func ServeFile

func ServeFile(w http.ResponseWriter, r *http.Request, name string)

ServeFile replies to the request with the contents of the named file or directory.

If the provided file or directory name is a relative path, it is interpreted relative to the current directory and may ascend to parent directories. If the provided name is constructed from user input, it should be sanitized before calling ServeFile.

As a precaution, ServeFile will reject requests where r.URL.Path contains a ".." path element; this protects against callers who might unsafely use filepath.Join on r.URL.Path without sanitizing it and then use that filepath.Join result as the name argument.

As another special case, ServeFile redirects any request where r.URL.Path ends in "/index.html" to the same path, without the final "index.html". To avoid such redirects either modify the path or use ServeContent.

Outside of those two special cases, ServeFile does not use r.URL.Path for selecting the file or directory to serve; only the file or directory provided in the name argument is used.

func VFS

func VFS() http.FileSystem

Types

type StaticFS

type StaticFS struct {
	StaticFolder    string
	TrimLeftPath    string
	CheckLocalFirst bool
	SkipVFS         bool
	// contains filtered or unexported fields
}

func (StaticFS) Open

func (fs StaticFS) Open(name string) (http.File, error)

type VDirectory

type VDirectory struct {
	// contains filtered or unexported fields
}

func (VDirectory) Open

func (dir VDirectory) Open(name string) (http.File, error)

type VFile

type VFile struct {
	Compressed string
	FileSize   int64
	ModifyTime int64
	IsFolder   bool

	Data     []byte
	FileName string
}

func (*VFile) Close

func (f *VFile) Close() error

func (*VFile) File

func (f *VFile) File() (http.File, error)

func (*VFile) IsDir

func (f *VFile) IsDir() bool

func (*VFile) ModTime

func (f *VFile) ModTime() time.Time

func (*VFile) Mode

func (f *VFile) Mode() os.FileMode

func (*VFile) Name

func (f *VFile) Name() string

func (*VFile) Readdir

func (f *VFile) Readdir(count int) ([]os.FileInfo, error)

func (*VFile) Size

func (f *VFile) Size() int64

func (*VFile) Stat

func (f *VFile) Stat() (os.FileInfo, error)

func (*VFile) Sys

func (f *VFile) Sys() interface{}

type VirtualFS

type VirtualFS struct{}

func (VirtualFS) Open

func (VirtualFS) Open(name string) (http.File, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL