Embed files in Go

Leo Gutiérrez
8 min readDec 22, 2020

Let’s try the new “embed” feature we are going to have in the Go 1.16 release. These will be very basic examples but will get you a grasp on how to use this great feature, we will also check how to use the embed.FS file system, symlinks (and hardlinks…), how to read multiple files or directories, wildcards and what a linter says about our code.

First, create a file that we can reach from our program:

0 🐧 leo@lein ~/go-embed $ cat hello.txt 
Hello
World!

A simple text file with two lines. To embed this file in our Go program we can use the…

--

--

Leo Gutiérrez

Hi! I am Leonardo Gutiérrez R., a passionate software developer, I hope you find the content in this blog interesting. I write about IT related stuff.