From 70398d275cad281bb55362632dd5a1ce7cb6e80e Mon Sep 17 00:00:00 2001 From: Franky W Date: Mon, 11 Apr 2022 15:31:46 +0200 Subject: [PATCH] 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` --- assets/assets.go | 13 +++---------- core/corehttp/gateway_indexPage.go | 4 ++-- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/assets/assets.go b/assets/assets.go index 579a8b2ca..e16c8ff17 100644 --- a/assets/assets.go +++ b/assets/assets.go @@ -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) } diff --git a/core/corehttp/gateway_indexPage.go b/core/corehttp/gateway_indexPage.go index 3bee4822b..fbea91649 100644 --- a/core/corehttp/gateway_indexPage.go +++ b/core/corehttp/gateway_indexPage.go @@ -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) }