Distributing data files with tools written in Go

302 views
Skip to first unread message

Aaron Jacobs

unread,
Jan 8, 2012, 8:38:46 PM1/8/12
to golang-nuts
Does anyone have tips on how to include data files with an easily installable
program written in Go?

For example, if I have a program that draws text onto pictures of cats, I may
want to include `cat.jpg` and `impact.ttf`. I'd like users to be able to say
simply:

goinstall github.com/foo/catsay

and have those files installed to e.g. `/usr/local/share`. Normally I would
use some sort of makefile trickery, but goinstall ignores makefiles.

Has anyone run into this situation, where you need to distribute more than
just a binary to make a tool work? How did you solve it?

Thanks,
Aaron

Andrew Gerrand

unread,
Jan 8, 2012, 8:55:18 PM1/8/12
to Aaron Jacobs, golang-nuts
On 9 January 2012 12:38, Aaron Jacobs <jac...@google.com> wrote:
> Does anyone have tips on how to include data files with an easily installable
> program written in Go?
>
> For example, if I have a program that draws text onto pictures of cats, I may
> want to include `cat.jpg` and `impact.ttf`. I'd like users to be able to say
> simply:
>
>    goinstall github.com/foo/catsay
>
> and have those files installed to e.g. `/usr/local/share`. Normally I would
> use some sort of makefile trickery, but goinstall ignores makefiles.

I would include a shell script with the program and ask users to run
it. It's not automatic, but then I'd be a little surprised if
goinstall were to install anything but Go source and object files.

> Has anyone run into this situation, where you need to distribute more than
> just a binary to make a tool work? How did you solve it?

There was another thread about this recently:

https://groups.google.com/d/topic/golang-nuts/XksK4klJ0Dg/discussion

An approach that isn't mentioned in that thread: use the go/build
package's FindTree function to locate the source path of your package.
There's an example of this in the Go Tour source:
http://code.google.com/p/go-tour/source/browse/gotour/local.go#63

Andrew

Adam Logghe

unread,
Jan 9, 2012, 1:03:01 AM1/9/12
to golan...@googlegroups.com
You could simply retrieve the data files via http on first run then cache them for subsequent runs?

Aaron Jacobs

unread,
Jan 9, 2012, 3:47:15 PM1/9/12
to Andrew Gerrand, golang-nuts
For the record, Andrew and I chatted and the best idea I heard was
simply using build.FindTree to find the tree containing the git clone
for my project, then grabbing the data files from src/my/package/. If
users use goinstall to install, this should work.

OmarShariffDontLikeIt

unread,
Jan 9, 2012, 3:44:03 PM1/9/12
to golang-nuts
For my projects I embed the binary files as go code. My Makefile
simply calls go-bindata:

https://github.com/jteeuwen/go-bindata
Reply all
Reply to author
Forward
0 new messages