Loving Go's built-in template libraries, currently I am just declaring the template as const string. How does one normally go about including larger more sophisticated template files? Ideally I prefer them to be inside the binary to simplify deployment.
Embedding static files in 2021 has become a bit easier since the release of Go 1.16. The new release comes with a new package embed
which provides a handy set of interface and methods to attach static file in go binaries
go version
# 1.16.x
# then
go doc embed
example in cks-cli software
Here's a solution that fulfills the need and prevents the hardship described by mbazon:
https://godoc.org/github.com/go-bindata/go-bindata
It compiles to binary, but when you're in "debug" mode, it reads your static assets directly from the disk.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With