4 ms·
I've written convenience http handlers that compile Go to js on demand (and report errors in the browser console & server stderr). I do something like this in t
by shurcooL 12y ago
I've written convenience http handlers that compile Go to js on demand (and report errors in the browser console & server stderr). I do something like this in the backend:
http.Handle("/assets/script.go.js", gopherjs_http.GoFiles("./assets/script.go"))
Then my html files (or templates that generate html via html/template package) include it with:
<script src="./assets/script.go.js" type="text/javascript"></script>.
That way, I can edit the ./assets/script.go file in my code editor (with goimports on save, autocomplete, etc.) with the server running. Whenever I refresh the page in the browser, new compiled JavaScript is loaded.
It's really nice to be able edit the Go script, css, html template and not need to restart the web server for effects to take place. Just refresh the page, and see new code running.
That's my workflow so far.
I have plans to improve that code so that it accesses the assets via a virtual file system interface, so that it's possible to have a debug version that hot-reloads all files from disk, and a release version that embeds the assets into the Go binary so it can run anywhere.
- Rapzid 12y agoVery interesting, so It's sort of a repl server. Using node.js you could even execute and return the results.. I'm starting to see how someone(who knows what they are doing) could create a POC LightTable plugin...