Hacker News new | ask | show | jobs
by lonk11 1014 days ago
Thanks for sharing!

I liked the idea of defining the handle path in the name of the template and the auto-reloading on change functionality.

I wish this was a stand-alone library that I could use in my custom Golang server. Do you know if something like this exists?

1 comments

I'm considering factoring it out into a general library, it should be rather easy. Would you be interested?

You can also see my previous project, go-htmx for a previous version of the idea, though its missing some features.

Yes, that would be useful. Basically, what you have in https://github.com/infogulch/caddy-xtemplate/blob/master/tem... - but without Caddy dependencies and with a way to use any router library (I use gorilla/mux).

I would make the templates library take a callback function for every public template: func(method, path string, template).

Then the user could add any custom logic to register the route handler and execute the template with any application specific inputs.

I'll have to think about that. It currently uses path parameters from the julienschmidt/httprouter router implementation, which I think are pretty important. How would you expect to define and receive path parameters?
gorilla/mux supports parameters in the path as well. For example: "/posts/{id:[0-9]+}"

Passing the parameters from the handler to the template could be left to the user of the library.