Documentation ¶
Overview ¶
Package vfshash offers a http.FileSystem that wraps an underlying http.FileSystem to make resources content-addressable by adding a truncated cryptographic digest to the file names.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AssetNames ¶
type AssetNames struct {
// contains filtered or unexported fields
}
AssetNames maps asset paths to their content-addressable equivalents.
Example ¶
package main import ( "net/http" "go.tmthrgd.dev/vfshash" ) var assets struct{ http.FileSystem } func main() { names := vfshash.NewAssetNames(assets.FileSystem) // returns /example-deadbeef.css names.Lookup("/example.css") // returns /does.not.exist.txt as is names.Lookup("/does.not.exist.txt") // opens /example-deadbeef.js names.Open("/example.js") }
Output:
func NewAssetNames ¶
func NewAssetNames(fs http.FileSystem) *AssetNames
NewAssetNames returns an AssetNames using the given http.FileSystem.
func (*AssetNames) IsContentAddressable ¶
func (n *AssetNames) IsContentAddressable() bool
IsContentAddressable reports whether the underlying http.FileSystem is using content-addressable names. This is the case when it was wrapped with FileSystem.
func (*AssetNames) Lookup ¶
func (n *AssetNames) Lookup(name string) string
Lookup returns the content-addressable name of an asset that matches the given name.
If the name isn't known, or the http.FileSystem wasn't wrapped with FileSystem, the name is returned as is.
type FileSystem ¶
type FileSystem struct {
// contains filtered or unexported fields
}
FileSystem wraps a http.FileSystem to make assets content-addressable by adding a truncated cryptographic digest to the file names.
Example ¶
package main import ( "log" "net/http" "github.com/shurcooL/vfsgen" "go.tmthrgd.dev/vfshash" ) func main() { fs := vfshash.NewFileSystem(http.Dir("assets")) err := vfsgen.Generate(fs, vfsgen.Options{}) if err != nil { log.Fatal(err) } }
Output:
func NewFileSystem ¶
func NewFileSystem(fs http.FileSystem) *FileSystem
NewFileSystem returns an FileSystem using the given http.FileSystem.