-1

I have a Go package that links to C library using CFLAGS for cgo. C library, in turn, requires local data file to work properly. It's prebuilt 3d-party library and option to set data file path is not available.

Everything works as expected if client of package is local and data is loaded by lib, but when I build & install package, data file is not copied.

Is there any option to put custom file near go package while installing package?

Anatolii
  • 1
  • 1

2 Answers2

0

Is there any option to put custom file near go package while installing package?

No there is not. Sorry. This has to be solved by other means like system package managers.

Volker
  • 40,468
  • 7
  • 81
  • 87
0

I would suggest using https://github.com/jteeuwen/go-bindata tool to compile that dependency into your main Go binary. This way you can then store multiple files inside your single binary (for different operating systems) and pick the right one on runtime. I use it in several projects - haven't found any problems with this approach.

go-bindata -o output_file.go input_data_directory/

and then to access it:

data, err := Asset("some_important_file")
if err != nil {
    // Asset was not found.
}

So, when you start your application - just copy the files from your inside Asset to the paths that your application is expecting. I hope that helps.

Deforciant
  • 51
  • 3