Live data from Hacker News

Show HN: Use Go's HTML/template to write React-like code

news.ycombinator.com

11–20 of 96 posts

Re: Show HN: Use Go's HTML/template to write React-like code

#11
post #9
post #3

Go's template system (both text/template and html/template) is pretty powerful. You can add custom functions and partial templates too. I use these concepts in https://docs.hofstadter.io to generate any code, not just frontend. Hugo uses the same system to do static site generation, which may be even closer to what you are showing. Helm templates is the epitome of the worst use (go/templating yaml files, I use CUE fo…

I love React too, but it pulls in a lot of dependencies and the dependencies need periodic maintenance. Sometimes you get the feeling that you're spending a significant chunk of your time not writing code but fighting with configs and dependency churn. Using Go's html/template definitely makes the UI feel dated because of re-rendering, but I rarely notice it in my side project. My next exploration is to use HTMX. I'm…

There eventually has to be JavaScript somewhere, and once you have to use that for any dynamic frontend, might as well use a proper JS/TS framework.

Not being a frontend person first, I have learned to choose whatever they are using these days. It will be hard to hire, onboard, and maintain anything that strays too far for the normal patterns they use.

Next has skyrocketed in popularity for a reason. It makes the React DX much better, losing a lot of the config hell from other framework/library amalgamations

Re: Show HN: Use Go's HTML/template to write React-like code

#12

This is nice. Thanks for sharing. When I heard "react" I immediately thought SPA and Event handling in the browser. This is more close to ASP .NET ( organizing views on the server side). This is very useful but this is not for handling events on the client. Thanks again for sharing.

Yes, it's more about organizing your UI code/templates similar to a React codebase than running Go code in browser.

I think apart from vDOM, a big contribution from React is how we organize code.

Re: Show HN: Use Go's HTML/template to write React-like code

#14
post #4

[off-topic comment but somewhat relevant for anyone choosing a lang/ecosystem] I noticed that the syntax highlighting for the Go html/template examples in the article is incomplete. We're using Go html/templates on a new project (within a team that does a lot of React frontend & some Python) so this kind of project seems like it would really suit, but a massive bugbear has been the very poor IDE-level syntax highligh…

In Jet Brains family IDEs (not sure how they call the go one) you can use Inject language or reference option to get most of editor support (inspections,highlighting,intellisense etc.) for snippets of one language embedd in files of another language. I've been using it with JS scripts inside custom xml for a while and it works pretty well.

Re: Show HN: Use Go's HTML/template to write React-like code

#15

This is nice. Thanks for sharing. When I heard "react" I immediately thought SPA and Event handling in the browser. This is more close to ASP .NET ( organizing views on the server side). This is very useful but this is not for handling events on the client. Thanks again for sharing.

Yeah this is more like go-template-jsx than "react"

Re: Show HN: Use Go's HTML/template to write React-like code

#16

Although I don’t know Go programming language, I do appreciate people making stuff using as minimal dependencies as possible. I’m glad that I’m not the only one who has this habit.

it kinda looks like a small PHP boilerplate. Except with GO you still need some code to make templates render

Re: Show HN: Use Go's HTML/template to write React-like code

#17
post #9

Earlier quoted context omitted.

I love React too, but it pulls in a lot of dependencies and the dependencies need periodic maintenance. Sometimes you get the feeling that you're spending a significant chunk of your time not writing code but fighting with configs and dependency churn. Using Go's html/template definitely makes the UI feel dated because of re-rendering, but I rarely notice it in my side project. My next exploration is to use HTMX. I'm…

There eventually has to be JavaScript somewhere, and once you have to use that for any dynamic frontend, might as well use a proper JS/TS framework. Not being a frontend person first, I have learned to choose whatever they are using these days. It will be hard to hire, onboard, and maintain anything that strays too far for the normal patterns they use. Next has skyrocketed in popularity for a reason. It makes the Rea…

> There eventually has to be JavaScript somewhere, and once you have to use that for any dynamic frontend, might as well use a proper JS/TS framework.

Yes, totally understand it's hard to escape JS in Web frontend. Even writing a simple dropdown requires a little bit of JS.

> Not being a frontend person first, I have learned to choose whatever they are using these days. It will be hard to hire, onboard, and maintain anything that strays too far for the normal patterns they use.

Since this is for my hobby project, it's more fun to be a irrational ;) I use standard React at work.

> Next has skyrocketed in popularity for a reason. It makes the React DX much better, losing a lot of the config hell from other framework/library amalgamations

Need to check Next again, I tried it many years back and it was good.

Re: Show HN: Use Go's HTML/template to write React-like code

#18
post #9
post #3

Go's template system (both text/template and html/template) is pretty powerful. You can add custom functions and partial templates too. I use these concepts in https://docs.hofstadter.io to generate any code, not just frontend. Hugo uses the same system to do static site generation, which may be even closer to what you are showing. Helm templates is the epitome of the worst use (go/templating yaml files, I use CUE fo…

I love React too, but it pulls in a lot of dependencies and the dependencies need periodic maintenance. Sometimes you get the feeling that you're spending a significant chunk of your time not writing code but fighting with configs and dependency churn. Using Go's html/template definitely makes the UI feel dated because of re-rendering, but I rarely notice it in my side project. My next exploration is to use HTMX. I'm…

HTMX + React style server rendered components would solve 80% of the use cases for a modern SPA. Keep going! This is a breath of fresh air for many simpler applications.

Re: Show HN: Use Go's HTML/template to write React-like code

#19
I am not a Go or frontend person, so I am a bit confused. I cannot figure out where any necessary JS is generated. The documentation for html/template only says it generated HTM, and a React alternative is presumably producing dynamic frontends (otherwise why would you be using react?). Am I missing something huge?

Re: Show HN: Use Go's HTML/template to write React-like code

#20
post #14
post #4

[off-topic comment but somewhat relevant for anyone choosing a lang/ecosystem] I noticed that the syntax highlighting for the Go html/template examples in the article is incomplete. We're using Go html/templates on a new project (within a team that does a lot of React frontend & some Python) so this kind of project seems like it would really suit, but a massive bugbear has been the very poor IDE-level syntax highligh…

In Jet Brains family IDEs (not sure how they call the go one) you can use Inject language or reference option to get most of editor support (inspections,highlighting,intellisense etc.) for snippets of one language embedd in files of another language. I've been using it with JS scripts inside custom xml for a while and it works pretty well.

Thanks for this; JetBrains stuff continues to amaze me. Its blessing and curse is the incredible breadth of functionality I keep learning about.
Post reply on HN