1

Does go build include other supporting files used in code and ships it along with exe? For ex:

--> input.go - contains go code to read input from text file
--> inpdata.txt

when we do go build, does the inpdata.txt files get shipped as well?
if these supporting files are excluded, how do they get their input values which are being fed from external files?

I am trying to build a binary (exe file precisely for win-OS) using Golang.
After reading some of the documentation can understand clearly that the go build command which produces the exe file for win-OS ignores _test.go files and all tesdata folders.
Also referred to go build binary package in the documentation, mentioned this is applicable only to non source files only.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
ehrktia
  • 170
  • 1
  • 4
  • 1
    In your example, `inpdata.txt` is not included in the output binary. Suppose your program read `inpdata.txt` by `ioutil.ReadAll("./inpdata.txt")`, when your binary is run, your program will actually look for `/inputdata.txt"`. `` is usually where you run your program. So you need to ensure your `inputdata.txt` is beside your binary. – Liyang Chen Jun 15 '19 at 07:22
  • @LiyangChen Is there a way to include inpdata.txt to the binary? Usecase: Let's say if I'm shipping this binary somewhere, how can I ensure that inpdata.txt is always present, without explicitly passing all the required resource files to server? – Shubham Gupta Mar 04 '22 at 08:20

1 Answers1

2

Does go build includes non go files in binary?

By default, no: you need to embed them.

There are several approaches:

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250