Problem to be solved

I want to embed the txt file containing all words into a single binary.

Source of information

Upgrade my project to use go 1.16

Install new go version;

Update my go mod:

1
go mod edit -go=1.16

Code

1
2
3
4
5
6
import _ "embed"
//go:embed words-en
var englishWords string

//go:embed words-cn
var chineseWords string

This will make these two strings available to the package, and the file will be packaged into the single compiled file upon build.