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`
Franky W committed
Apr 11, 2022 at 15:31 UTC
70398d275cad281bb55362632dd5a1ce7cb6e80e
2 files changed
+5
-12
assets/assets.go
+3
-10
@@ -20,7 +20,7 @@ import (
20
)
21
22
//go:embed init-doc dir-index-html/dir-index.html dir-index-html/knownIcons.txt
23
-var dir embed.FS
23
+var Asset embed.FS
24
25
// AssetHash a non-cryptographic hash of all embedded assets
26
var AssetHash string
@@ -43,7 +43,7 @@ func init() {
43
return nil
44
}
45
46
- file, err := dir.Open(path)
46
+ file, err := Asset.Open(path)
47
if err != nil {
48
return err
49
}
@@ -58,13 +58,6 @@ func init() {
58
AssetHash = strconv.FormatUint(sum.Sum64(), 32)
59
}
60
61
-// Asset loads and returns the asset for the given name.
62
-// It returns an error if the asset could not be found or
63
-// could not be loaded.
64
-func Asset(f string) ([]byte, error) {
65
- return dir.ReadFile(f)
66
-}
67
-
61
// SeedInitDocs adds the list of embedded init documentation to the passed node, pins it and returns the root key
62
func SeedInitDocs(nd *core.IpfsNode) (cid.Cid, error) {
63
return addAssetList(nd, initDocPaths)
@@ -84,7 +77,7 @@ func addAssetList(nd *core.IpfsNode, l []string) (cid.Cid, error) {
77
basePath := path.IpfsPath(dirb.Cid())
78
79
for _, p := range l {
87
- d, err := Asset(p)
80
+ d, err := Asset.ReadFile(p)
81
if err != nil {
82
return cid.Cid{}, fmt.Errorf("assets: could load Asset '%s': %s", p, err)
83
}
core/corehttp/gateway_indexPage.go
+2
-2
@@ -94,7 +94,7 @@ func hasDNSLinkOrigin(gwURL string, path string) bool {
94
var listingTemplate *template.Template
95
96
func init() {
97
- knownIconsBytes, err := assets.Asset("dir-index-html/knownIcons.txt")
97
+ knownIconsBytes, err := assets.Asset.ReadFile("dir-index-html/knownIcons.txt")
98
if err != nil {
99
panic(err)
100
}
@@ -121,7 +121,7 @@ func init() {
121
}
122
123
// Directory listing template
124
- dirIndexBytes, err := assets.Asset("dir-index-html/dir-index.html")
124
+ dirIndexBytes, err := assets.Asset.ReadFile("dir-index-html/dir-index.html")
125
if err != nil {
126
panic(err)
127
}