albrow / jobs

A persistent and flexible background jobs library for go.
MIT License
499 stars 47 forks source link

Use go generate to convert lua script files to strings #13

Closed albrow closed 9 years ago

albrow commented 9 years ago

Over at albrow/zoom, it was brought to my attention that reading scripts from a file at runtime can cause problems for people using certain dependency managers, or people who want to release a binary executable. See PRs https://github.com/albrow/zoom/pull/9, https://github.com/albrow/zoom/pull/10, and https://github.com/albrow/zoom/pull/11.

The solution I came up with was to use a small script (compatible with go generate) to read the contents from the .lua file and write them to a generated file as strings. I'm going to port a similar solution over to albrow/jobs. It will be a little bit more complicated because jobs uses templates for string constants in the lua scripts, but the general idea is the same. This is targeted for version 0.3.0 and will hopefully be released in the next couple days.

epelc commented 9 years ago

@albrow go-bindata is a popular solution for this. It's more often used for embedding website files into a binary but it works well with any files you need to embed.

Essentially it works by turning files into .go files with the original file content in a string. They also give you a bunch of helper func's to make the strings easy to use.

albrow commented 9 years ago

@epelc I am aware of go-bindata. It's very cool and I'm definitely going to add it to my toolbelt. We discussed it at albrow/zoom#10, and I think it's a bit overkill for this particular use case. The solution I have in mind is very similar to albrow/zoom#11, so I've already put in most of the work. It has less overhead, can never cause runtime errors, and generates code that is easier to understand. And it reduces the reliance on third-party dependencies.

epelc commented 9 years ago

@albrow Ahh I didn't know you started something already.

Also cool zoom package. You have some really nice projects.

albrow commented 9 years ago

@epelc thanks! Btw this is now incorporated in version 0.3.0 on master.