donseba / go-htmx

Seamless HTMX integration in golang applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Middleware and/or NewHandler?

Gys opened this issue · comments

commented

Hi

The relation between the middleware handler and Newhandler is confusing?

In the middleware comment it says:
// MiddleWare is a middleware that adds the htmx request header to the context
// deprecated: htmx will retrieve the headers from the request by itself using htmx.NewHandler(w, r)

Then in the Pokedex example only the middleware is used (could make sense, probably older example). However, in the README both are used?

You are correct, it is a bit misleading. I started initially with the middleware version but the NewHandler basically does the same.

I left the middleware instruction for the moment and will be deprecated for version 2.

If you feel like making a PR to update the Pokedex then go ahead, otherwise I will pick it up when I have an update ready.

Thanks for reporting though!

commented

I am using only the Newhandler and that works fine indeed, thanks!

A version 2? Curious for what you think that can be improved ;)

I've added a pull request to add SSE. I initially wanted to do websockets, but it is difficult to do it without using external packages. So this was the next best thing. 😅

commented

For my application I also decided to use SSE for exactly the same reason :)
I used this as a manager: https://github.com/romanm-perun/gin-sse-example/
I assign a unique channel (UUID) to each client and that does the job.

Is there a specific reason for you to implement a more specific HTMX version of an SSE manager? Like I said, my universal version works as expected. But maybe I missed something.

well the package you mentioned is gin specific ;)

there is no solid reason to have it in here, however since SSE is a compelling feature htmx provides it made sense to add a simple/basic integration without needing to depend on anything else.