3 ms·
Show HN: Go Template Preview – Powered by WebAssembly
- joeblubaugh 4y agoDoes it handle defining functions? I can’t get them to work.
- ricardbejarano 4y agoI'm afraid it cannot, since those functions would need to be compiled into WASM first, and that's something the browser can't do. What I could add, though, is a bunch of "standard" functions (like the ones found in Hugo, for example). Noted!
- eatonphil 4y agoIf you already have Go libraries compiling to wasm working then you could just embed a Go interpreter like yaegi [0]. [0] https://github.com/traefik/yaegi https://github.com/traefik/yaegi
- pjmlp 4y agoBesides the comment regarding using a Go interpreter, you can definitely compile inside of the browser and then load that WASM module into the current session.
- isaacimagine 4y agoUsing which compiler?
- pjmlp 4y agoTime to learn how to write one? I didn't say there is already a Go compiler that supports such workflow, rather that the infrastructure doesn't forbid it.
- ridruejo 4y agohttps://www.google.com/amp/s/golangexample.com/go-compiler-running-entirely-in-your-browser/amp/ https://www.google.com/amp/s/golangexample.com/go-compiler-r... Haven’t tried the above, just an example. Tinygo is the one commonly used in the Wasm ecosystem
- tekronis 4y agoThanks for making this. Maybe add an option that also exposes additional template functions from sprig: https://github.com/Masterminds/sprig https://github.com/Masterminds/sprig
- boramalper 4y agoInteresting that it's easier to run Go in browser using WebAssembly than to write a templating engine that uses Go's syntax in JS from scratch. :)
- colordrops 4y agoIs it either interesting or easier though?
- deleted 4y ago[deleted]
- cyberpunk 4y agoThis is awesome. Cheers!
- seanwilson 4y agoThis is cool! Do you think you could get Hugo to run in the browser this way so you could show live-previews in the browser without having to run Hugo locally?
- ricardbejarano 4y agoIt... should, i think? I'll try! Binary size is the main issue with Go WASM, the binary on this is 4MB, and it only does templating. TinyGo won't work because it doesn't have reflect (which I need for parsing arbitrary JSON). But I'll give it a spin. Thanks!
- drgo 4y agoNice Most recent release of Tinygo supports JSON decoding https://tinygo.org/docs/reference/lang-support/stdlib/ https://tinygo.org/docs/reference/lang-support/stdlib/
- randomguy011 4y agoHi @ricardbejarano First of all, I really interested with this project and I see there is a room for improvement, mind to open source the code? thanks randomguy011
- SergeAx 4y agoGreat project, well-bounded and insightful! Do you think about making it open source? I was thinking about trying to use another JSON library and make it work with tinygo, but don't want to repeat the work.