Embed files at compile time
How to embed files into goshs
Info
For this to work you will have to compile goshs yourself. See the section Build yourself for instructions.
You can embed files at compile time and ship them with your version of goshs. Any file that is in the folder embedded in the project root will be compiled into the binary and will be available while running. There is already a file called example.txt in the folder by default to demonstrate the feature.
To compile just use make build-<os>
, like for example make build-linux
for a version running on linux.
You can then retrieve the file browsing to /file/path?embedded
. In addition to that you can use the flag -e
to show the embedded files in the frontend.
user@host:~$ ./goshs -e
INFO [2024-07-04 18:01:46] Download embedded file at: /example.txt?embedded
INFO [2024-07-04 18:01:46] Serving on interface eth0 bound to 10.137.0.27:8000
INFO [2024-07-04 18:01:46] Serving on interface lo bound to 127.0.0.1:8000
INFO [2024-07-04 18:01:46] Serving HTTP from /
INFO [2024-07-04 18:01:46] - "GET /example.txt?embedded HTTP/1.1"
user@host:~$ curl http://127.0.0.1:8000/example.txt?embedded
This is an example for an embedded file on compilation time. If you place any other file here before compiling using the Makefile, then it will be added to the goshs binary and will be available when running it.