Change assets.Asset from a func to the embed.FS

This removes the delegation to the function and requires all callers
that used the `asset.Asset` func to access to asset via the `embed.FS`
This commit is contained in:
Franky W 2022-04-11 15:31:46 +02:00 committed by Jorropo
parent 9210c08fa6
commit 70398d275c
2 changed files with 5 additions and 12 deletions

View File

@ -20,7 +20,7 @@ import (
)
//go:embed init-doc dir-index-html/dir-index.html dir-index-html/knownIcons.txt
var dir embed.FS
var Asset embed.FS
// AssetHash a non-cryptographic hash of all embedded assets
var AssetHash string
@ -43,7 +43,7 @@ func init() {
return nil
}
file, err := dir.Open(path)
file, err := Asset.Open(path)
if err != nil {
return err
}
@ -58,13 +58,6 @@ func init() {
AssetHash = strconv.FormatUint(sum.Sum64(), 32)
}
// Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func Asset(f string) ([]byte, error) {
return dir.ReadFile(f)
}
// SeedInitDocs adds the list of embedded init documentation to the passed node, pins it and returns the root key
func SeedInitDocs(nd *core.IpfsNode) (cid.Cid, error) {
return addAssetList(nd, initDocPaths)
@ -84,7 +77,7 @@ func addAssetList(nd *core.IpfsNode, l []string) (cid.Cid, error) {
basePath := path.IpfsPath(dirb.Cid())
for _, p := range l {
d, err := Asset(p)
d, err := Asset.ReadFile(p)
if err != nil {
return cid.Cid{}, fmt.Errorf("assets: could load Asset '%s': %s", p, err)
}

View File

@ -94,7 +94,7 @@ func hasDNSLinkOrigin(gwURL string, path string) bool {
var listingTemplate *template.Template
func init() {
knownIconsBytes, err := assets.Asset("dir-index-html/knownIcons.txt")
knownIconsBytes, err := assets.Asset.ReadFile("dir-index-html/knownIcons.txt")
if err != nil {
panic(err)
}
@ -121,7 +121,7 @@ func init() {
}
// Directory listing template
dirIndexBytes, err := assets.Asset("dir-index-html/dir-index.html")
dirIndexBytes, err := assets.Asset.ReadFile("dir-index-html/dir-index.html")
if err != nil {
panic(err)
}