One of the most anticipated features of Go 1.16 is the support for embedding files and folders into the application binary at compile-time without usi

How to Use go:embed in Go 1.16

submited by
Style Pass
2021-06-09 20:30:06

One of the most anticipated features of Go 1.16 is the support for embedding files and folders into the application binary at compile-time without using an external tool. This feature is also known as go:embed, and it gets its name from the compiler directive that makes this functionality possible: //go:embed.

With it, you can embed all web assets required to make a frontend application work. The build pipeline will simplify since the embedding step does not require any additional tooling to get all static files needed in the binary. At the same time, the deployment pipeline is predictable since you don’t need to worry about deploying the static files and the problems that come with that, such as: making sure the relative paths are what the binary expects, the working directory is the correct one, the application has the proper permissions to read the files, etc. You just deploy the application binary and start it, and everything else works.

Note: If you need to, you can download a newer version of Go using GoLand either while creating the project or via Settings/Preferences | Go | GOROOT | + | Download …

Leave a Comment