Documentation
¶
Index ¶
- Constants
- func FileServer(fsys *SourceFs) http.Handler
- func FormatName(filename, hash string) string
- func ParseName(filename string) (base, hash string)
- type CompressedReader
- type DiskFile
- type DiskFileInfo
- type DiskReadFS
- func (d *DiskReadFS) CreateTempSourceDir() (string, error)
- func (d *DiskReadFS) FileHash(excludeGlob []string) (string, error)
- func (d *DiskReadFS) Glob(pattern string) (matches []string, err error)
- func (d *DiskReadFS) Open(name string) (fs.File, error)
- func (d *DiskReadFS) ReadFile(name string) ([]byte, error)
- func (d *DiskReadFS) Reset()
- func (d *DiskReadFS) Stat(name string) (fs.FileInfo, error)
- func (d *DiskReadFS) StatNoSpec(name string) (fs.FileInfo, error)
- func (d *DiskReadFS) StaticFiles() []string
- type DiskWriteFS
- type ReadableFS
- type SourceFs
- func (f *SourceFs) ClearCache()
- func (f *SourceFs) Glob(pattern string) ([]string, error)
- func (f *SourceFs) HashName(name string) string
- func (f *SourceFs) Open(name string) (fs.File, error)
- func (f *SourceFs) ParseFS(funcMap template.FuncMap, patterns ...string) (*template.Template, error)
- func (f *SourceFs) ParseName(filename string) (base, hash string)
- func (f *SourceFs) Stat(name string) (fs.FileInfo, error)
- func (f *SourceFs) StaticFiles() []string
- type WorkFs
- type WritableFS
- type WritableSourceFs
Constants ¶
const COMPRESSION_TYPE = "br" // brotli uses br as the encoding type
Variables ¶
This section is empty.
Functions ¶
func FileServer ¶
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 ¶
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.
Types ¶
type CompressedReader ¶
type DiskFile ¶
type DiskFile struct {
// contains filtered or unexported fields
}
func NewDiskFile ¶
func NewDiskFile(name string, data []byte, fi DiskFileInfo) *DiskFile
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 ¶
func NewDiskReadFS ¶
func (*DiskReadFS) CreateTempSourceDir ¶
func (d *DiskReadFS) CreateTempSourceDir() (string, error)
func (*DiskReadFS) Reset ¶
func (d *DiskReadFS) Reset()
func (*DiskReadFS) StatNoSpec ¶ added in v0.7.6
func (d *DiskReadFS) StatNoSpec(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
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) StatNoSpec(name string) (fs.FileInfo, error) // Stat the FS without looking at spec files 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) HashName ¶
HashName returns the hash name for a path, if exists. Otherwise returns the original path.
func (*SourceFs) Open ¶
Open returns a reference to the named file. If name is a hash name then the underlying file is used.
func (*SourceFs) ParseName ¶
ParseName splits formatted hash filename into its base & hash components.
func (*SourceFs) StaticFiles ¶
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