[HN Gopher] Show HN: Go Template Preview - Powered by WebAssembly
___________________________________________________________________
Show HN: Go Template Preview - Powered by WebAssembly
Author : ricardbejarano
Score : 86 points
Date : 2022-06-12 11:19 UTC (11 hours ago)
(HTM) web link (gotemplate.io)
(TXT) w3m dump (gotemplate.io)
| seanwilson wrote:
| This 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 wrote:
| It... 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!
| joeblubaugh wrote:
| Does it handle defining functions? I can't get them to work.
| ricardbejarano wrote:
| I'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!
| pjmlp wrote:
| Besides 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 wrote:
| Using which compiler?
| ridruejo wrote:
| 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
| pjmlp wrote:
| Time 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.
| eatonphil wrote:
| If 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
| cyberpunk wrote:
| This is awesome. Cheers!
| boramalper wrote:
| Interesting 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. :)
| [deleted]
| colordrops wrote:
| Is it either interesting or easier though?
| tekronis wrote:
| Thanks for making this. Maybe add an option that also exposes
| additional template functions from sprig:
| https://github.com/Masterminds/sprig
| randomguy011 wrote:
| Hi @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
___________________________________________________________________
(page generated 2022-06-12 23:00 UTC)