What is go-bindata and why do we need it?
go-bindata converts any text or binary file into Go source code, which is useful for embedding data into Go programs. So you can build your whole project into 1 binary file for easier delivery.
ParseFiles works only with files on the filesystem, so we need to implement a port to work with both approaches: files or go-bindata. Files:
go build && ./go-bindata-tpl <!DOCTYPE html> <html lang="en"> <body> Hello </body> </html>
Generate templates with go-bindata
We need to install go-bindata CLI and generate a .go file from our templates:
go get -u github.com/jteeuwen/go-bindata/... go-bindata -o tpl.go tpl
I prefer to add last command to
//go:generate go-bindata -o tpl.go tpl
Use go-bindata templates
I made it by providing a flag
./go-bindata-tpl -go-bindata <!DOCTYPE html> <html lang="en"> <body> Hello </body> </html>
go-bindatayou can simplify your deployment with only one binary file.
go-bindatacan give you a little faster templates reading.
- Note that if you use
ParseFilesyou have to change it to work with