logoalt Hacker News

How I use HTMX with Go

103 pointsby gnabgibyesterday at 7:55 PM21 commentsview on HN

Comments

nzoschkeyesterday at 10:18 PM

Love Go + HTMX. I pair it with a-h/templ for a bit more type safety on the template, components and partials.

I just shared my whole toolkit too [1], I call it the "GUS stack" -- Go, Unix, SQLite. Inspired heavily by the exe.dev "GUTS" stack [2] but with HTMX instead of Typescript.

Some other Go components in the kit...

- cockroachdb/errors for errors with stack traces

- templ for type-safe HTML templates (with htmx for reactivity and tailwindcss for CSS)

- fuego for an OpenAPI spec generated from web handlers

- sqlc for type-safe code generated from SQL

- modernc.org/sqlite for a pure Go sqlite library

- goose for SQL and Go migrations

- dbos for durable workflows in SQLite

- rod for Chrome / CDP testing and automation

Feels so productive coding, agentic coding, and building and deploying binaries with this stack.

[1] https://housecat.com/blog/the-gus-stack-go-unix-sqlite

[2] https://exe.dev/docs/guts

show 1 reply
xp84yesterday at 10:11 PM

I used HTMX on a recent project and really enjoyed it. As a person who knows how the Web worked before the invention of AngularJS and React, I deeply appreciate being able to build actual pages and minimize the amount of JS that has to exist. Vanilla JS works fine, but HTMX basically just substitutes for a lot of boilerplate that you'd otherwise have to create just to do the same event handler stuff over and over.

If you're curious, and you too aren't in love with the "Modern frontend" philosophy, I would recommend trying out HTMX. Of note, the first examples of HTMX on the HTMX site are really basic, but it's much more powerful with a bit more learning.

show 1 reply
arjietoday at 12:45 AM

Huge fan of HTMX. Agent can reason about components well. Iteration is good and testing story is solid. Very happy with results. I use Rust/Go (prefer Go - safer package ecosystem - no build time code running) with HTMX.

androiddrewyesterday at 10:28 PM

I love Alex Edwards. His books and Learn go with tests were my first introduction to the language. Still recommend to this day.

I'm feel inspired to convert some old stuff to HTMX

show 1 reply
sethops1yesterday at 10:54 PM

We use this[1] little package, which enables chaining together HTMX responses that can be based on an HTML template file, an HTML raw string, or plain text. All but the first being OOB targets. Real example:

  return htmx.Write(w,

    &htmx.Template{
      FS:       htmx.FS(ui.HTMX, "parts"),
      Filename: "arrows.html",
      Fields:   []any{thread, up},
    },

    &htmx.Component{
      HTML: `
        <div {{$count := index . 0 -}} {{- $thread := index . 1 -}}
          hx-swap-oob=true
          id="points-{{$thread}}"
          class="points">{{$count}} points</div>`,
      Fields: []any{count, thread},
    },

  )
[1] https://github.com/cattlecloud/webtools/tree/main/htmx
overflowyyesterday at 11:45 PM

While I love both Go and Alex, my experience with HTMX has always ended up being disappointing.

I think the best way to put it, when I'm working with HTMX it feels like the complexity of the codebase is growing at a 2:1 rate compared to the app itself. I always end up with some weird edge case that I can not come out of without some weird hack.

I get why people dislike Node packages, HTMX feels like it's an overcompensating response to that. But the time you save by not having to wrestle with JSON is tripled when you try to make the app actually look or feel good. It takes me 2 minutes to slap together a Mantine template [1] and tap into some of the best UI components, then I can embed the built static assets and end up with the same single Go binary.

[1] https://github.com/mantinedev/vite-min-template

show 1 reply
smallerfishyesterday at 11:11 PM

I wrote a framework for my own use that uses Kotlin + HTMX - https://github.com/reubenfirmin/zoned. The goal was to see if I could create webapps that were fully typed, end to end. It uses Kotlinx.html, which provides a jsx-ish dsl for writing html.

I did the first 90% by hand, and have done the last 10% (and README) with Claude, just to get it out there.

artooroyesterday at 11:27 PM

Go + Datastar is simpler, I much prefer it.

show 1 reply
pbjerkesethyesterday at 10:41 PM

HTMX is excellent. We made it a long way at Convictional[1] with HTMX + AlpineJS, but the eventual transition of our product into lots of live collaborative surfaces had us feeling like we had pushed the envelope as far as we could under modern startup constraints. Unfortunately, frontier models have really hurt development with budding tech that doesn't have the training data presence of things like React.

[1] https://get.convictional.com/

_superposition_yesterday at 10:36 PM

Nice post. Gotta love the GOTH stack

show 1 reply
typesafeJyesterday at 9:54 PM

[dead]