Lets assume that running go install -v importpath builds an executable and installs it into $GOPATH/bin/program. The go tool is unable to install resource files. When I run the program, I would like it to access some resource files that are under $GOPATH/src/importpath.
What is the best way of accessing such resource files from the installed executable?
This question has been asked multiple times on the go-nuts mailing list. The
gotool doesn’t offer a direct way to distribute additional resources at the moment. However, there are two workarounds available:write a simple script (awk should be sufficient) to convert any file into a
.gofile which just contains a single string constant and embed the file directly into the binary. This approach is used by the Camlistore project for example (camlistored/ui/fileembed.go). go-bindata does similar things.go-tour and many other projects are currently using the Import function of the
go/buildpackage to search through allsrc/folders listed in$GOPATHand$GOROOTto find the correct path of the package sources. Example: http://code.google.com/p/go-tour/source/browse/gotour/local.go?r=996704f8ef9e63949b3bc4d94b613ec4a7b5d99a#53