Open richmoore opened 8 years ago
I added build instructions to the readme. Please let me know if you have any problems, or can suggest improvements to them.
I have experienced same problem, even after following your instructions. Binary is created, but no styles. Stefan
master308 - Are you saying the binary runs, and serves some html, but that the page is not styled?
Yes, exactly. When I go to the address that is being hosted I get page which is without styles.
That's what I got too even after trying the steps you listed. I'm going to have another go with a complete new GOPATH so I can get the full set of commands I'm running (including installing the dependencies) in case I'm doing something silly.
The fact that the html itself is getting served narrows down the problem quite a bit. It shows that when the server code attempts to access the compiled-in resources, it succeeds and the html template part of the compiled in static directory tree is present and correct. The code fetches the templates using direct programmatic access to the compiled assets. However the css, fonts and js are handled differently by the served html including links to them. When thse link url requests arrive at the server it is supposed to redirect them to the standard file server which in turn has been constructed to serve from a virtual file system backed by the compiled assets.
Could you look inside the gobindata.go file and confirm that your generated one does show some evidence of also knowing about the css and js files in the tree?
If we find that the contents look to be complete, then the smoking gun is pointing at either some problem with the way I've set up the go server routing config whereby any urls that refer to static pages are routed to the standard file server. Or a problem with how I,ve used AssetFS to create a virtual file system around the compiled in assets. Needless to say it works for me. Could anyone else who has got their copy working put their hand up so we can assess if its maybe environment related?
It is written that my bindata.go is built using the following data
// Code generated by go-bindata. // sources: // static/css/bootstrap-theme.min.css // static/css/bootstrap.min.css // static/fonts/glyphicons-halflings-regular.eot // static/fonts/glyphicons-halflings-regular.svg // static/fonts/glyphicons-halflings-regular.ttf // static/fonts/glyphicons-halflings-regular.woff // static/fonts/glyphicons-halflings-regular.woff2 // static/js/bootstrap.min.js // static/js/jquery.min.js // templates/maingui.html
Hi,
follwoing your instructions I get a file "resources.go" instead of "bindata.go". The content is not correct:
// Code generated by go-bindata.
// sources:
// bindata.go
// readme.md
// DO NOT EDIT!
Running main.go gives me exact the same problem as master308. Where do I reference the bindata.go file? Didn't find it...I guess the bindata.go included in your repo is used instead of my newly build resource file (09:49), as main.go starts even when deleting my generated file.
➜ godesktopgui git:(master) ✗ ll resources
-rw-rw-r-- 1 700K Jun 2 08:40 bindata.go
-rw-rw-r-- 1 287 Jun 2 08:40 readme.md
-rw-rw-r-- 1 1020K Jun 2 09:49 resources.go
Regards
If I move the 2 directories static and templates into the resources folder, the resources.go files seems to be generated correctly.
➜ godesktopgui git:(master) ✗ ll resources
-rw-rw-r-- 1 699K Jun 2 10:11 resources.go
drwxrwxr-x 5 4,0K Jun 2 08:40 static
drwxrwxr-x 2 4,0K Jun 2 08:40 templates
➜ godesktopgui git:(master) ✗ head -n 20 resources/resources.go
// Code generated by go-bindata.
// sources:
// static/css/bootstrap-theme.min.css
// static/css/bootstrap.min.css
// static/fonts/glyphicons-halflings-regular.eot
// static/fonts/glyphicons-halflings-regular.svg
// static/fonts/glyphicons-halflings-regular.ttf
// static/fonts/glyphicons-halflings-regular.woff
// static/fonts/glyphicons-halflings-regular.woff2
// static/js/bootstrap.min.js
// static/js/jquery.min.js
// templates/maingui.html
// DO NOT EDIT!
package main
import (
"bytes"
"compress/gzip"
"fmt"
Sorry for spamming, some more details, the main.go starts, page is shown (only the html, without styles) and go gives following errors:
➜ godesktopgui git:(master) ✗ go run main.go
To see the GUI, visit this URL with your Web Browser:
http://localhost:47066/thegui
2016/06/02 10:44:39 http: panic serving [::1]:51984: runtime error: invalid memory address or nil pointer dereference
goroutine 18 [running]:
net/http.(*conn).serve.func1(0xc820128000, 0x7f7a4f061000, 0xc820126000)
/home/user/.gvm/gos/go1.5/src/net/http/server.go:1287 +0xb5
github.com/elazarl/go-bindata-assetfs.(*AssetFS).Open(0xc820015410, 0xc82011b295, 0x1c, 0x0, 0x0, 0x0, 0x0)
/home/user/.gvm/pkgsets/go1.5/global/src/github.com/elazarl/go-bindata-assetfs/assetfs.go:148 +0x22e
net/http.serveFile(0x7f7a508a9cd0, 0xc8200c16b0, 0xc820118540, 0x7f7a508a8b08, 0xc820015410, 0xc82011b294, 0x1d, 0x1)
/home/user/.gvm/gos/go1.5/src/net/http/fs.go:359 +0x158
net/http.(*fileHandler).ServeHTTP(0xc82000b1b0, 0x7f7a508a9cd0, 0xc8200c16b0, 0xc820118540)
/home/user/.gvm/gos/go1.5/src/net/http/fs.go:483 +0x19c
net/http.(*ServeMux).ServeHTTP(0xc820014d80, 0x7f7a508a9cd0, 0xc8200c16b0, 0xc820118540)
/home/user/.gvm/gos/go1.5/src/net/http/server.go:1699 +0x17d
net/http.serverHandler.ServeHTTP(0xc820020180, 0x7f7a508a9cd0, 0xc8200c16b0, 0xc820118540)
/home/user/.gvm/gos/go1.5/src/net/http/server.go:1862 +0x19e
net/http.(*conn).serve(0xc820128000)
/home/user/.gvm/gos/go1.5/src/net/http/server.go:1361 +0xbee
created by net/http.(*Server).Serve
/home/user/.gvm/gos/go1.5/src/net/http/server.go:1910 +0x3f6
2016/06/02 10:44:39 http: panic serving [::1]:51986: runtime error: invalid memory address or nil pointer dereference
I am using Ubuntu and gvm.
I have solved the issue by mixing in the example from https://rockfloat.com/post/learning-golang-templates.html.
Can you post an explanation of the root cause error you found, or the minimum viable remedy to what I have in this repo, or even a push request? I have been very frustrated by being unable to reproduce the problem.
Hi,
I was not able to find the root cause of the issue: the static files where not served.
Now it works; I tried to do a pull request on your repo, but I was not allowed to do this, that's why I have cloned it into my space.
Regards
Hello Peter,
I found the root cause of the problem. It's basically the layout of the project. We are simply not able to (re-)generate a working version of bindata.go with the current project layout.
Here is the reason:
The filesystem layout is:
./templates/maingui.tml
./static/css/*.css
which is also reflected in bindata.go. The main html page is served via
resources.Asset("templates/maingui.html")
That's the reason why it works.
The static assets are served via
http.Handle("/static/", http.FileServer(virtual_fs))
which strips off the leading /static/
which is the reason why it's not working. To make the code work I only deleted (by hand) the static/
prefix in bindata.go:
var _bindata = map[string]func() (*asset, error){
"css/bootstrap-theme.min.css": staticCssBootstrapThemeMinCss,
"css/bootstrap.min.css": staticCssBootstrapMinCss,
"fonts/glyphicons-halflings-regular.eot": staticFontsGlyphiconsHalflingsRegularEot,
"fonts/glyphicons-halflings-regular.svg": staticFontsGlyphiconsHalflingsRegularSvg,
"fonts/glyphicons-halflings-regular.ttf": staticFontsGlyphiconsHalflingsRegularTtf,
"fonts/glyphicons-halflings-regular.woff": staticFontsGlyphiconsHalflingsRegularWoff,
"fonts/glyphicons-halflings-regular.woff2": staticFontsGlyphiconsHalflingsRegularWoff2,
"js/bootstrap.min.js": staticJsBootstrapMinJs,
"js/jquery.min.js": staticJsJqueryMinJs,
"templates/maingui.html": templatesMainguiHtml,
}
I don't have any idea whether there is a clever combination of command line options to achieve this during generation.
Thanks for your enlightening example.
Best regards
Hi, rethinking my explanation, I believe that I'm wrong.
Nevertheless the change is working?!
BR
BTW: I'm using go-1.6.2
I found two unrelated root causes for this issue and have fixed them. Please read about both because the second of them is dependent on if you refreshed the dependency on github.com/elazarl/go-bindata-assetfs and when.
I'll leave the issue open until someone confirms that it now works for them.
The first is that the build instructions for this project were a bit wrong. I've fixed them and also simplified it to remove the uneccessary complexity of using a separate package for the compiled-in resources.
The second was that the assetfs project had introduced a new structure member for the AssetFS type, called AssetInfo. This has to be initialised by the code that instantiates an AssetFS, but the only effect of not doing so, was silent failure to serve static resources like the stylesheets. This api change was introduced Aug 26th 2015.
The comments trail for this issue implies that some people are using a version of AssetInfo from before that change date (like I was), else reorganising the static resources would not have solved the problem.
Please let me know how you get on.
If I just do a go build then I don't seem to get any styles etc. compiled into the app. Could you outline the correct build instructions?