Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
tpl
 
 
 
 
 
 
 
 
 
 
 
 

README.md

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.

html/template

html/template's functions Parse, 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:generate go-bindata -o tpl.go tpl

Use go-bindata templates

I made it by providing a flag -go-bindata:

./go-bindata-tpl -go-bindata
<!DOCTYPE html>
<html lang="en">
<body>
Hello
</body>
</html>

Conclusion

  • With go-bindata you can simplify your deployment with only one binary file.
  • go-bindata can give you a little faster templates reading.
  • Note that if you use ParseFiles you have to change it to work with Assert function.

About

How to use go-bindata with html/template

Resources

License

Releases

No releases published
You can’t perform that action at this time.