infogulch / xtemplate

A html/template-based hypertext preprocessor and rapid application development web server written in Go.
Apache License 2.0
74 stars 1 forks source link

nats caddy #1

Closed gedw99 closed 7 months ago

gedw99 commented 1 year ago

this might match up with your TODO requirements ?

https://github.com/sandstorm/caddy-nats-bridge

infogulch commented 1 year ago

I didn't know about that thanks for the reference.

I'm still not exactly sure how I want the integration to go. But basically I'd like some way to do live updates to an htmx page with SSE or websockets.

gedw99 commented 1 year ago

the caddy-nats-bridge is definitely not for what you want then.

You might like this one as it's designed to work with Pub sub systems. I use it because it supports web and fat golang apps. So she and http is all I need for networking then.

https://github.com/tmaxmax/go-sse is one of the many use libs that is designed to have a message broker under it like NATS, but it does not have it let.

https://github.com/r3labs/sse is mega popular one too with also have a golang client

infogulch commented 1 year ago

I'd like to do it all within a template definition if possible, loosely basing it on this guide: https://thedevelopercafe.com/articles/server-sent-events-in-go-595ae2740c7a

{{define "SSE:GET /events"}}
{{$userid := .Req.Header.Get "Remote-User"}}
{{range $msg := .Subscribe (printf "user.%s.feed_counts" $userid)}}
id: {{$msg.Id}}
data: {{.Template "feed_count_component" ($msg) | toJson}}
{{-.Flush}}
{{end}}
{{end}}

This might require a different buffering strategy compared to what xtemplate does today.

gedw99 commented 1 year ago

sounds good

infogulch commented 1 year ago

SSE is implemented now. You can see some examples in the integration/templates directory if you're curious what it looks like:

sse.html

hotreload.html

gedw99 commented 1 year ago

https://github.com/charbonnierg/caddy-nats for nats does auth call out

gedw99 commented 1 year ago

https://www.youtube.com/watch?v=Ds71axJRFm0&ab_channel=Synadia is excellent for showing how rot use the new stuff in ants 2.0. Auth Call out demo as well.

infogulch commented 7 months ago

It's been a minute, but I pushed an early version of the nats provider to the next branch, along with the skeleton of an IM demo:

https://github.com/infogulch/xtemplate/blob/next/test/templates/nats/index.html

gedw99 commented 7 months ago

It's been a minute, but I pushed an early version of the nats provider to the next branch, along with the skeleton of an IM demo:

https://github.com/infogulch/xtemplate/blob/next/test/templates/nats/index.html

this looks like a really great start. I will have a play with this tonight.

infogulch commented 7 months ago

The latest release adds nats and natskv providers, so I'm closing as completed. 🎉

I'm curious to hear feedback about it.

infogulch commented 6 months ago

The way this is implemented makes it impossible to configure a nats kv and nats conn that use the same internal server from json or cli config. Not sure how to resolve this.