Comments (14)
from go-bindata-assetfs.
What happens when you do that with go-bindata?
from go-bindata-assetfs.
I don't know, but it is pretty obvious from the code above that assetFS() is looping through all the Children and just returning the first one.
from go-bindata-assetfs.
@awalterschulze I believe I read somewhere on go-bindata that if you define the folder such as "css/..." "fonts/..." "js/..."
all subdirectories are also included. I shall check to see where I found that information.
from go-bindata-assetfs.
@awalterschulze https://github.com/jteeuwen/go-bindata/issues/67
from go-bindata-assetfs.
@awalterschulze does this solve your problem?
from go-bindata-assetfs.
No, not at all.
Why is the loop in the code above only returning the first one and not all folders in the list?
from go-bindata-assetfs.
I'm seeing the same issue, it only looks in the first directory returned by the 'range' map lookup
from go-bindata-assetfs.
This seems totally broken. The error I'm getting, I think, is caused by this. I don't understand why the selecting of assets is done this way, but the lack of any sort of error handling code makes this really hard to debug when you're developing with this package. I started out generating the files like this:
go-bindata-assetfs -debug -prefix ../app/static/ ../app/static/...
then trying to use it like this:
controller.PathPrefix("/static/").Handler(
http.StripPrefix("/static/",
http.FileServer(assetFS())))
I ended up with a bunch of 500 errors with empty responses; nothing printed to the console or the response. So now to debug, I did some hackery:
controller.PathPrefix("/static/").Handler(
http.StripPrefix("/static/",
http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
fmt.Println("got request for: ", r.URL.Path)
f, err := assetFS().Open(r.URL.Path)
if err != nil {
fmt.Println(err)
}
fi, _ := f.Stat()
http.ServeContent(
rw, r,
fi.Name(),
fi.ModTime(),
f)
})))
That prints this:
got request for: img/gps.svg
open index.html/img/gps.svg: no such file or directory
In my auto-generated file, this is an excerpt:
"glyphicons-halflings-regular.woff2": &bintree{fontsGlyphiconsHalflingsRegularWoff2, map[string]*bintree{}},
}},
"img": &bintree{nil, map[string]*bintree{
"gps.svg": &bintree{imgGpsSvg, map[string]*bintree{}},
}},
"index.html": &bintree{indexHtml, map[string]*bintree{}},
"js": &bintree{nil, map[string]*bintree{
"angular-moment.min.js": &bintree{jsAngularMomentMinJs, map[string]*bintree{}},
"angular-moment.min.js.map": &bintree{jsAngularMomentMinJsMap, map[string]*bintree{}},
"angular-resource.min.js": &bintree{jsAngularResourceMinJs, map[string]*bintree{}},
Same results without debug mode. When I use this, everything works fine:
controller.PathPrefix("/static/").Handler(
http.StripPrefix("/static/",
http.FileServer(http.Dir("../app/static/"))))
...and because of that, I would expect that this package would work too.
from go-bindata-assetfs.
a simple workaround is adding an additional parent directory around the <dir1>... <dir2>...
directories and then just referencing <parent_dir>...
from go-bindata-assetfs.
Why is a workaround needed when there is a clear bug here?
from go-bindata-assetfs.
I would suggest fixing the bug, but offering a tip for those of us relying on the library currently. it saved me frustration; the ISSUE has been open for quite some time...
from go-bindata-assetfs.
Hi all.
I don't have time to fix bugs myself, but I'll be happy to accept PR.
As I said in other places, I keep this library mainly as people already use it.
I think that today there are better solutions for embedding assets in Go, e.g., rice.go, and I don't see too much point with investing effort in another one.
Thanks,
from go-bindata-assetfs.
For those having this problem, there is an approach to avoid this bug.
Given @hut8 's command:
go-bindata-assetfs -debug -prefix ../app/static/ ../app/static/...
... the command may be changed to:
go-bindata-assetfs -debug -prefix ../app/ ../app/static/...
... so that the (only) directory at the root of the assets is static/
and assetFS reads what is inside it.
The bug is in the assetFS()
function generated by the go-bindata-assetfs command
: this function loops on "root directories" in the assets and directly returns the first one.
I will not do a PR because it would break existing setups.
Such a PR would change the following lines:
for k := range _bintree.Children {
return &assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: assetInfo, Prefix: k}
}
to:
return &assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: assetInfo, Prefix: ""}
from go-bindata-assetfs.
Related Issues (20)
- Gzip headers HOT 2
- bindata_assefts fails with golint HOT 1
- Loaded assets from go-bindata via assetfs.AssetFS are empty HOT 1
- Why FakeFile and not AssetInfo()'s os.FileInfo? HOT 2
- AssetInfo - runtime error: invalid memory address HOT 3
- binddata.go file cannot be found if output location is changed
- does not handle -o properly HOT 12
- Protecting users of obsolete API (pre AssetInfo)
- Please tag and version this project HOT 1
- Error when building the project
- Undefined type in generated file
- os package imported twice HOT 3
- Impossible to use theres no Assetfs function exported from the produced go code HOT 2
- assetFS is not exportable HOT 3
- Can I manage file in AssetFS?
- Import order to pass linting HOT 3
- some access error when use in windows HOT 2
- Tag/Release v1.0.1 HOT 2
- Cannot declare multiple directories with `go-bindata-assetfs` or a single child.
- go get is deprecated in go version 1.17 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-bindata-assetfs.