Documentation
¶
Overview ¶
Package zipfs provides an implementation of the net/http.FileSystem interface based on the contents of a ZIP file. It also provides the FileServer function, which returns a net/http.Handler that serves static files from a ZIP file. This HTTP handler exploits the fact that most files are stored in a ZIP file using the deflate compression algorithm, and that most HTTP user agents will accept deflate as a content-encoding. When possible the HTTP handler will send the compressed file contents back to the user agent without having to decompress the ZIP file contents.
Index ¶
- Constants
- func BuildHtaccessChain(htaccessHandlers map[string]*HtaccessHandler, requestPath string, ...) (http.Handler, bool)
- func Cgi(w http.ResponseWriter, r *http.Request, phpBin string, scriptFileName string, ...)
- func EmptyFileServer(baseAPIPath string, urlPrepend string, isVerbose bool, indexExts []string, ...) http.Handler
- func FileServer(fs *FileSystem, baseAPIPath string, urlPrepend string, isVerbose bool, ...) http.Handler
- func FileServers(fs []*FileSystem, baseAPIPath string, urlPrepend string, isVerbose bool, ...) http.Handler
- type ArchiveData
- type DirExistsFunc
- type FileExistsFunc
- type FileSystem
- type HtaccessHandler
- type Mount
- type MountList
- type RewriteCond
- type RewriteRule
- type SimpleResponseData
Constants ¶
const ( CtxUsingHtaccess contextKey = "using-htaccess" CtxPerformedRewrite contextKey = "performed-rewrite" )
Variables ¶
This section is empty.
Functions ¶
func BuildHtaccessChain ¶
func EmptyFileServer ¶
func FileServer ¶
func FileServer(fs *FileSystem, baseAPIPath string, urlPrepend string, isVerbose bool, indexExts []string, mimeExts map[string]string) http.Handler
FileServer returns a HTTP handler that serves HTTP requests with the contents of the ZIP file system. It provides slightly better performance than the http.FileServer implementation because it serves compressed content to clients that can accept the "deflate" compression algorithm.
Types ¶
type ArchiveData ¶
type DirExistsFunc ¶
type FileExistsFunc ¶
type FileSystem ¶
type FileSystem struct {
// contains filtered or unexported fields
}
FileSystem is a file system based on a ZIP file. It implements the http.FileSystem interface.
func New ¶
func New(name string) (*FileSystem, error)
New will open the Zip file specified by name and return a new FileSystem based on that Zip file.
func NewArchiveData ¶
func NewArchiveData(archiveData ArchiveData) (*FileSystem, error)
func NewFromReaderAt ¶
func NewFromReaderAt(readerAt io.ReaderAt, size int64, closer io.Closer, filePath string) (*FileSystem, error)
NewFromReaderAt will open the Zip file accessible by readerAt with the given size. The closer, if not nil, will be called when the file system is closed.
func (*FileSystem) Close ¶
func (fs *FileSystem) Close() error
Close closes the file system's underlying ZIP file and releases all memory allocated to internal data structures.
type HtaccessHandler ¶
type HtaccessHandler struct {
Rules []RewriteRule
RewriteBase string
Next http.Handler
// contains filtered or unexported fields
}
HtaccessHandler wraps the parsed .htaccess rules
func CreateHtaccessHandler ¶
func CreateHtaccessHandler(filepath string, next http.Handler, fileExists *FileExistsFunc, dirExists *DirExistsFunc) (*HtaccessHandler, error)
ParseHTAccess parses a .htaccess file and returns a handler
func (*HtaccessHandler) ServeHTTP ¶
func (h *HtaccessHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler
type Mount ¶
type Mount struct {
FilePath *string `json:"filePath"`
ArchiveData *ArchiveData `json:"archiveData"`
}
type RewriteCond ¶
type RewriteCond struct {
TestString string
CondPattern string
Pattern *regexp.Regexp
Flags map[string]string
}
RewriteCond represents a RewriteCond directive
type RewriteRule ¶
type RewriteRule struct {
Pattern *regexp.Regexp
Substitution string
Flags map[string]string
Conditions []RewriteCond
}
RewriteRule represents a single Apache RewriteRule
type SimpleResponseData ¶
type SimpleResponseData struct {
Message string `json:"msg"`
}