DEV Community

Cover image for How to compile non-go file into your binary

Posted on

How to compile non-go file into your binary


If you're new to compiled languages then you probably wondered "Will my .html or .png files compile into my binary", well to answer that it's not possible but there is a little 'hack' to do it, and im going to show you how to do it!

First thing, make you sure that you already have Go installed and also you'll have to install/download the software called "GoFiles" made by me.

to install GoFiles, follow these steps:

Now that you've installed GoFiles, we can continue. Let's say you created a new go project stored at $HOME/go/src/TestGoFiles, in your directory there is a file called 'test.txt' and you want to include it in your 'main.go' binary code. You'll have to add the following lines to your 'main.go' file:

Then when you want to compile your code, you won't use the command 'go build' or 'go run' but instead you'll use 'gofiles compile ./' !

Now try it by yourself and you'll see that the file got compiled, if you want more examples on how to host the file on a web server for example, see the examples at

If you got any problem with the software, feel free to open an issue at

Top comments (0)