appfs

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const COMPRESSION_TYPE = "br" // brotli uses br as the encoding type

Variables

This section is empty.

Functions

func FileServer

func FileServer(fsys *SourceFs) http.Handler

FileServer returns an http.Handler for serving FS files. It provides a simplified implementation of http.FileServer which is used to aggressively cache files on the client since the file hash is in the filename.

Because FileServer is focused on small known path files, several features of http.FileServer have been removed including canonicalizing directories, defaulting index.html pages, precondition checks, & content range headers.

func FormatName

func FormatName(filename, hash string) string

FormatName returns a hash name that inserts hash before the filename's extension. If no extension exists on filename then the hash is appended. Returns blank string the original filename if hash is blank. Returns a blank string if the filename is blank.

func ParseName

func ParseName(filename string) (base, hash string)

ParseName splits formatted hash filename into its base & hash components.

Types

type CompressedReader

type CompressedReader interface {
	ReadCompressed() (data []byte, compressionType string, err error)
}

type DiskFile

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

func NewDiskFile

func NewDiskFile(name string, data []byte, fi DiskFileInfo) *DiskFile

func (*DiskFile) Close

func (f *DiskFile) Close() error

func (*DiskFile) Name

func (f *DiskFile) Name() string

func (*DiskFile) Read

func (f *DiskFile) Read(dst []byte) (int, error)

func (*DiskFile) Seek

func (f *DiskFile) Seek(offset int64, whence int) (int64, error)

func (*DiskFile) Stat

func (f *DiskFile) Stat() (fs.FileInfo, error)

type DiskFileInfo

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

func (*DiskFileInfo) IsDir

func (fi *DiskFileInfo) IsDir() bool

func (*DiskFileInfo) ModTime

func (fi *DiskFileInfo) ModTime() time.Time

func (*DiskFileInfo) Mode

func (fi *DiskFileInfo) Mode() fs.FileMode

func (*DiskFileInfo) Name

func (fi *DiskFileInfo) Name() string

func (*DiskFileInfo) Size

func (fi *DiskFileInfo) Size() int64

func (*DiskFileInfo) Sys

func (fi *DiskFileInfo) Sys() any

type DiskReadFS

type DiskReadFS struct {
	*types.Logger
	// contains filtered or unexported fields
}

func NewDiskReadFS

func NewDiskReadFS(logger *types.Logger, root string, specFiles types.SpecFiles) *DiskReadFS

func (*DiskReadFS) CreateTempSourceDir

func (d *DiskReadFS) CreateTempSourceDir() (string, error)

func (*DiskReadFS) FileHash

func (d *DiskReadFS) FileHash(excludeGlob []string) (string, error)

func (*DiskReadFS) Glob

func (d *DiskReadFS) Glob(pattern string) (matches []string, err error)

func (*DiskReadFS) Open

func (d *DiskReadFS) Open(name string) (fs.File, error)

func (*DiskReadFS) ReadFile

func (d *DiskReadFS) ReadFile(name string) ([]byte, error)

func (*DiskReadFS) Reset

func (d *DiskReadFS) Reset()

func (*DiskReadFS) Stat

func (d *DiskReadFS) Stat(name string) (fs.FileInfo, error)

func (*DiskReadFS) StaticFiles

func (d *DiskReadFS) StaticFiles() []string

type DiskWriteFS

type DiskWriteFS struct {
	*DiskReadFS
}

func (*DiskWriteFS) Remove

func (d *DiskWriteFS) Remove(name string) error

func (*DiskWriteFS) Write

func (d *DiskWriteFS) Write(name string, bytes []byte) error

type ReadableFS

type ReadableFS interface {
	fs.FS
	fs.ReadFileFS
	fs.GlobFS
	// Stat returns the stats for the named file.
	Stat(name string) (fs.FileInfo, error)
	Reset()                                        // Used to reset the file system transaction for the DbFs, no-op for others
	StaticFiles() []string                         // Return list of static files
	FileHash(excludeGlob []string) (string, error) // Return a hash of the source file contents
	CreateTempSourceDir() (string, error)          // Create a temporary directory with source files
}

ReadableFS is the interface for the file system used by app to read source files

type SourceFs

type SourceFs struct {
	ReadableFS
	Root string
	// contains filtered or unexported fields
}

SourceFs is the implementation of source file system

func NewSourceFs

func NewSourceFs(dir string, fs ReadableFS, isDev bool) (*SourceFs, error)

func (*SourceFs) ClearCache

func (f *SourceFs) ClearCache()

func (*SourceFs) Glob

func (f *SourceFs) Glob(pattern string) ([]string, error)

func (*SourceFs) HashName

func (f *SourceFs) HashName(name string) string

HashName returns the hash name for a path, if exists. Otherwise returns the original path.

func (*SourceFs) Open

func (f *SourceFs) Open(name string) (fs.File, error)

Open returns a reference to the named file. If name is a hash name then the underlying file is used.

func (*SourceFs) ParseFS

func (f *SourceFs) ParseFS(funcMap template.FuncMap, patterns ...string) (*template.Template, error)

func (*SourceFs) ParseName

func (f *SourceFs) ParseName(filename string) (base, hash string)

ParseName splits formatted hash filename into its base & hash components.

func (*SourceFs) Stat

func (f *SourceFs) Stat(name string) (fs.FileInfo, error)

func (*SourceFs) StaticFiles

func (f *SourceFs) StaticFiles() []string

type WorkFs

type WorkFs struct {
	WritableFS
	Root string
}

WorkFs is the implementation of work file system

func NewWorkFs

func NewWorkFs(dir string, fs WritableFS) *WorkFs

NewWorkFs creates a new work file system

type WritableFS

type WritableFS interface {
	ReadableFS
	Write(name string, bytes []byte) error
	Remove(name string) error
}

WritableFS is the interface for the writable underlying file system used by AppFS

type WritableSourceFs

type WritableSourceFs struct {
	*SourceFs
}

func (*WritableSourceFs) Remove

func (w *WritableSourceFs) Remove(name string) error

func (*WritableSourceFs) Write

func (w *WritableSourceFs) Write(name string, bytes []byte) error

Jump to

Keyboard shortcuts

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