legit
legit copied to clipboard
Embed the templates into the binary
Hey, after building the binary and moving it in ~/.local/bin it didn't work, since you need the templates.
I would be cool if the default templates were used when you don't specify a templates directory by embedding them using embed.FS
...
2022/12/22 20:24:39 http: panic serving 127.0.0.1:50144: html/template: pattern matches no files: `templates/*`
...
That would be great yeah—if you'd like to give it a go, patches welcome.
I have implemented this change in https://github.com/icyphox/legit/pull/18. But I just realized that we don't need template path in config.yaml now that it's embedded. Also I embedded static files in binary which I think are better left outside.
I will fix this tomorrow evening, it's quite late here.
I have implemented this change in #18. But I just realized that we don't need template path in
config.yamlnow that it's embedded. Also I embedded static files in binary which I think are better left outside.I will fix this tomorrow evening, it's quite late here.
You should embed the static resources in the binary too IMO 👌
I have implemented this change in #18. But I just realized that we don't need template path in
config.yamlnow that it's embedded. Also I embedded static files in binary which I think are better left outside.I will fix this tomorrow evening, it's quite late here.
We should keep the static and template directories configurable and loadable from the filesystem, if they exist. That would make the initial deployment easy, but if anyone wants to customise the templates or the assets they still can by creating files at the expected paths instead of having to maintain a fork.
We should keep the static and template directories configurable and loadable from the filesystem, if they exist.
I was thinking if the path for static and/or template is not set in config then we load respective files from binary. If they are set then we load from file system.
We should keep the static and template directories configurable and loadable from the filesystem, if they exist.
I was thinking if the path for
staticand/ortemplateis not set inconfigthen we load respective files from binary. If they are set then we load from file system.
Ah yeah, that would be a nice way to do it.
Implementation for embed of templates and static is complete. Please review #18 If you have any feedback let me know.
We should keep the
staticandtemplatedirectories configurable and loadable from the filesystem, if they exist. That would make the initial deployment easy, but if anyone wants to customise the templates or the assets they still can by creating files at the expected paths instead of having to maintain a fork.
Normally for most of my projects, I support using/loading templating / static resources from disk by "debug mode", production builds setups always use the embedded versions, unless an option like -t/--theme /path/to/theme is supplied.
Maybe leggit can adopt a similar pattern? 🤔
I've proposed something to that end in the PR, #18. It's relatively straightforward nowadays to do a real filesystem with fallback to embedded assets thanks to the fs.FS interface.
This was actually my initial approach but there were some issues so I decided to go with current implementation. I will take another look at it when I have some free time.