This is a created article in which the information may have evolved or changed.
In the development of Golang, we sometimes want to package some external dependent files into a binary program. For example, when I developed the LESSGO web framework, I wanted to package the extension package swagger (the front end of an automated API document) into a project file, which would reduce dependencies and improve code stability. The implementation steps are as follows:
- Download a third-party package for two Golang
go get github.com/jteeuwen/go-bindata/...go get github.com/elazarl/go-bindata-assetfs/...
Compiling the Go-bindata-assetfs.exe file using the "Go Install" command
Perform "Go-bindata-assetfs.exe views/..." Write all files in the./views directory to the Bindata_assetfs.go file
A function named Assetfs () is provided in the Bindata_assetfs.go file, which returns the HTTP containing the contents of the view file. Filesystem Interface Instance
For example, static file routing is called:
http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(assetFS)))