Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Go Template Preview – Powered by WebAssembly (gotemplate.io)
102 points by ricardbejarano on June 12, 2022 | hide | past | favorite | 16 comments


Thanks for making this. Maybe add an option that also exposes additional template functions from sprig: https://github.com/Masterminds/sprig


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


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?


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!


Nice Most recent release of Tinygo supports JSON decoding https://tinygo.org/docs/reference/lang-support/stdlib/


Does it handle defining functions? I can’t get them to work.


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!


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


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.


Using which compiler?


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


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.


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


This is awesome. Cheers!


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. :)


Is it either interesting or easier though?




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: