Git Product home page Git Product logo

Comments (14)

awalterschulze avatar awalterschulze commented on August 19, 2024 2

from go-bindata-assetfs.

elazarl avatar elazarl commented on August 19, 2024

What happens when you do that with go-bindata?

from go-bindata-assetfs.

awalterschulze avatar awalterschulze commented on August 19, 2024

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.

markwallsgrove avatar markwallsgrove commented on August 19, 2024

@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.

markwallsgrove avatar markwallsgrove commented on August 19, 2024

@awalterschulze https://github.com/jteeuwen/go-bindata/issues/67

from go-bindata-assetfs.

markwallsgrove avatar markwallsgrove commented on August 19, 2024

@awalterschulze does this solve your problem?

from go-bindata-assetfs.

awalterschulze avatar awalterschulze commented on August 19, 2024

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.

curtpm avatar curtpm commented on August 19, 2024

I'm seeing the same issue, it only looks in the first directory returned by the 'range' map lookup

from go-bindata-assetfs.

hut8 avatar hut8 commented on August 19, 2024

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.

schmohlio avatar schmohlio commented on August 19, 2024

a simple workaround is adding an additional parent directory around the <dir1>... <dir2>... directories and then just referencing <parent_dir>...

from go-bindata-assetfs.

awalterschulze avatar awalterschulze commented on August 19, 2024

Why is a workaround needed when there is a clear bug here?

from go-bindata-assetfs.

schmohlio avatar schmohlio commented on August 19, 2024

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.

elazarl avatar elazarl commented on August 19, 2024

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.

tiramiseb avatar tiramiseb commented on August 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.