legit icon indicating copy to clipboard operation
legit copied to clipboard

Embed the templates into the binary

Open DeluxeOwl opened this issue 2 years ago • 10 comments

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/*`
...

DeluxeOwl avatar Dec 22 '22 18:12 DeluxeOwl

That would be great yeah—if you'd like to give it a go, patches welcome.

icyphox avatar Dec 26 '22 07:12 icyphox

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.

quaintdev avatar Jan 05 '23 21:01 quaintdev

I have implemented this change in #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.

You should embed the static resources in the binary too IMO 👌

prologic avatar Jan 05 '23 22:01 prologic

I have implemented this change in #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.

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.

daenney avatar Jan 06 '23 15:01 daenney

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.

quaintdev avatar Jan 06 '23 15:01 quaintdev

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.

Ah yeah, that would be a nice way to do it.

daenney avatar Jan 06 '23 16:01 daenney

Implementation for embed of templates and static is complete. Please review #18 If you have any feedback let me know.

quaintdev avatar Jan 06 '23 17:01 quaintdev

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.

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? 🤔

prologic avatar Jan 06 '23 23:01 prologic

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.

daenney avatar Jan 07 '23 12:01 daenney

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.

quaintdev avatar Jan 09 '23 08:01 quaintdev