Documentation
¶
Overview ¶
Package fs contains abstractions not provided by io/fs needed to provide services such as writing files and utility functions that can be useful.
OpenFiler provides OpenFile() similar to the "os" package when you need to write file data.
Writer provides a WriteFile() similar to the "os" package when you want to write an entire file at once.
OFOption provides a generic Option type for implementations of OpenFile() to use.
This package also introduces a Merge() function to allow merging of filesystem content into another filesystem and the ability to tranform the content in some way (like optimizations).
Using Merge to optimize embed.FS Javascript into a subdirectory "js":
optimized := simple.New(simple.WithPearson()) err := Merge( optimized, somePkg.Embeded, "/js/", WithTransform( func(name string, content []byte) ([]byte, error){ // If we are in debug mode, we want unoptimized Javascript if debug { return content, nil } switch path.Ext(name){ case "js": return optimizeJS(content) case "go": return nil, nil } return content, nil }, ), ) if err != nil { // Do something } optimized.RO()
The above code takes embedded Javscript stored in an embed.FS and if we are not in a debug mode, optimized the Javscript with an optimizer. This allows us to keep our embed.FS local to the code that directly uses it and create an overall filesystem for use by all our code while also optmizing that code for production.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DefaultLogger ¶
type DefaultLogger struct{}
DefaultLogger provides a default Logger implementation that uses Go's standard log.Println/Printf calls.
func (DefaultLogger) Printf ¶
func (DefaultLogger) Printf(format string, v ...interface{})
func (DefaultLogger) Println ¶
func (DefaultLogger) Println(v ...interface{})
type FileTransform ¶
FileTransform gives the base name of a file and the content of the file. It returns the content that MAY be transformed in some way. If this return a nil for []byte and a nil error, this file is skipped.
type Logger ¶
type Logger interface { Println(v ...interface{}) Printf(format string, v ...interface{}) }
Logger provides the minimum interface for a logging client.
type MergeOption ¶
type MergeOption func(o *mergeOptions)
MergeOption is an optional argument for Merge().
func WithTransform ¶
func WithTransform(ft FileTransform) MergeOption
WithTransform instructs the Merge() to use a FileTransform on the files it reads before writing them to the destination.
type MkdirAllFS ¶
type MkdirAllFS interface { OpenFiler // MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. // The permission bits perm (before umask) are used for all directories that MkdirAll creates. // If path is already a directory, MkdirAll does nothing and returns nil. MkdirAll(path string, perm fs.FileMode) error }
MkdirAllFS provides a filesystem that impelments MkdirAll(). An FS not implementing this is expected to create the directory structure on a file write.
type OFOption ¶
type OFOption func(o interface{}) error
OFOption is an option for the OpenFiler.OpenFile() call. The passed "o" arg is implementation dependent.
type OpenFiler ¶
type OpenFiler interface { fs.FS // OpenFile opens the file at name with fs.FileMode. The set of options is implementation // dependent. The fs.File that is returned should be type asserted to gain access to additional // capabilities. If opening for ReadOnly, generally the standard fs.Open() call is better. OpenFile(name string, perm fs.FileMode, options ...OFOption) (fs.File, error) }
OpenFiler provides a more robust method of opening a file that allows for additional capabilities like writing to files. The fs.File and options are generic and implementation specific. To gain access to additional capabilities usually requires type asserting the fs.File to the implementation specific type.
type Remove ¶
type Remove interface { // Remove removes the named file or (empty) directory. If there is an error, it will be of type *PathError. Remove(name string) error // RemoveAll removes path and any children it contains. It removes // everything it can but returns the first error it encounters. // If the path does not exist, RemoveAll returns nil (no error). // If there is an error, it will be of type *fs.PathError. RemoveAll(path string) error }
Remove provides a filesystem that implements Remove() and RemoveAll().
type Writer ¶
type Writer interface { OpenFiler // WriteFile writes a file's content to the file system. This implementation may // return fs.ErrExist if the file already exists. The FileMode // may or may not be honored by the implementation. WriteFile(name string, data []byte, perm fs.FileMode) error }
Writer provides a filesystem implememnting OpenFiler with a simple way to write an entire file.
Directories
¶
Path | Synopsis |
---|---|
io
|
|
cache
Package cache provides helpers for building a caching system based on io/fs.FS.
|
Package cache provides helpers for building a caching system based on io/fs.FS. |
cache/disk
Package disk provides an FS that wraps the johnsiilver/fs/os package to be used for a disk cache that expires files.
|
Package disk provides an FS that wraps the johnsiilver/fs/os package to be used for a disk cache that expires files. |
cache/groupcache
Package groupcache is an fs.FS wrapper for caching purposes built around Brad Fitzpatrick's groupcache.
|
Package groupcache is an fs.FS wrapper for caching purposes built around Brad Fitzpatrick's groupcache. |
cache/groupcache/peerpicker
Package peerpicker provides a groupcache.PeerPicker that utilizes a LAN peer discovery mechanism and sets up the groupcache to use the HTTPPool for communication between nodes.
|
Package peerpicker provides a groupcache.PeerPicker that utilizes a LAN peer discovery mechanism and sets up the groupcache to use the HTTPPool for communication between nodes. |
So.... | |
cache/redis
Package redis provides an io/fs.FS implementation that can be used in our cache.FS package.
|
Package redis provides an io/fs.FS implementation that can be used in our cache.FS package. |
cloud/azure/blob
Package blob is an implementation of the io.FS for Azure blob storage.
|
Package blob is an implementation of the io.FS for Azure blob storage. |
cloud/azure/blob/auth/msi
Package msi provides authentication methods using Microsoft Service Identities.
|
Package msi provides authentication methods using Microsoft Service Identities. |
os
Package os provides an io.FS that is implemented using the os package.
|
Package os provides an io.FS that is implemented using the os package. |