gopherfs

package
v0.0.0-...-dc8c21b Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dir

type Dir string

A Dir implements FileSystem using the native file system restricted to a specific directory tree.

Dir is based on http.Dir and has the same caveats.

func (Dir) Open

func (d Dir) Open(name string) (File, error)

Open implements FileSystem using os.Open, opening files for reading rooted and relative to the directory d.

type File

type File interface {
	io.Closer
	io.Reader
	Readdir(count int) ([]os.FileInfo, error)
	Stat() (os.FileInfo, error)
}

A File is returned by a FileSystem's Open method and can be served by the FileServer implementation.

The methods should behave the same as those on an *os.File.

type FileServer

type FileServer struct {
	MinPerms os.FileMode
	AllowDot bool
	Log      gopher.Logger

	// Rewrite allows you to intercept the selector and manipulate it. You must return
	// the original selector if you don't wish to change it. If allowed is not true,
	// the resource will appear to not exist.
	Rewrite func(selector string) (out string, allowed bool)

	// Change the file name used to represent the gophermap for a directory. Defaults to
	// 'gophermap'.
	GopherMapFile string

	// If the gophermap is autogenerated, the contents of this file is prepended as 'i'
	// lines. Defaults to 'gopherbanner'.
	BannerFile string

	// ItemType is called first in the chain of type resolvers. It allows you full control
	// of the item type for a given selector.
	//
	// Return 'gopher.NoItemType, true' if you want to fall back to the default matching.
	// The selector can be used directly with your FileSystem implementation if you want
	// to inspect the file.
	//
	// Return 'gopher.NoItemType, false' if you want the FileServer to pretend the
	// selector does not exist.
	ItemType func(selector string) (item gopher.ItemType, allowed bool)

	// ExtensionTypes is used to look up the ItemType by file extension (including the
	// leading '.') if ItemType is not set or returns gopher.NoItemType.
	ExtensionTypes map[string]gopher.ItemType
	// contains filtered or unexported fields
}

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

func New

func New(fs FileSystem, base string) *FileServer

func (*FileServer) ServeGopher

func (fsrv *FileServer) ServeGopher(ctx context.Context, w gopher.ResponseWriter, r *gopher.Request)

func (*FileServer) ServeGopherMeta

func (fsrv *FileServer) ServeGopherMeta(ctx context.Context, w gopher.MetaWriter, r *gopher.Request)

type FileSystem

type FileSystem interface {
	// Open would probably be better named OpenURLPath, but is 'Open' for compatibility
	// with http.FileServer
	Open(urlPath string) (File, error)
}

A FileSystem implements access to a collection of named files. The elements in a file path are separated by forward slash ('/') characters, regardless of the host OS.

Jump to

Keyboard shortcuts

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