aboutsummaryrefslogtreecommitdiff
path: root/handler.go
diff options
context:
space:
mode:
authorGravatar Abhinav Gupta <mail@abhinavg.net> 2019-01-03 13:55:15 -0800
committerGravatar GitHub <noreply@github.com> 2019-01-03 13:55:15 -0800
commit2bf0f688f895aa19f976051e30b967a6187e27b4 (patch)
tree6e3425e59eafaf05546e348bd2182a08a7fbe0f0 /handler.go
parenta3b25c3f7761b0c8d4cd3871e335a32a929f8dda (diff)
downloadsally-2bf0f688f895aa19f976051e30b967a6187e27b4.tar.gz
sally-2bf0f688f895aa19f976051e30b967a6187e27b4.tar.zst
sally-2bf0f688f895aa19f976051e30b967a6187e27b4.zip
template: Bundle in binary with bindata (#36)
This uses go-bindata/go-bindata to bundle the template in the binary. I also realized that the handler test was now broken because we were checking the exact contents of the index page in the test. This change fixes that too.
Diffstat (limited to 'handler.go')
-rw-r--r--handler.go17
1 files changed, 6 insertions, 11 deletions
diff --git a/handler.go b/handler.go
index 0c95b43..4c409fb 100644
--- a/handler.go
+++ b/handler.go
@@ -8,17 +8,12 @@ import (
"github.com/julienschmidt/httprouter"
)
-var indexTemplate, packageTemplate *template.Template
-
-func init() {
- tmpls := template.Must(template.ParseGlob("templates/*.html"))
- if indexTemplate = tmpls.Lookup("index.html"); indexTemplate == nil {
- panic("Missing index.html template")
- }
- if packageTemplate = tmpls.Lookup("package.html"); packageTemplate == nil {
- panic("Missing package.html template")
- }
-}
+var (
+ indexTemplate = template.Must(
+ template.New("index.html").Parse(string(MustAsset("templates/index.html"))))
+ packageTemplate = template.Must(
+ template.New("package.html").Parse(string(MustAsset("templates/package.html"))))
+)
// CreateHandler creates a Sally http.Handler
func CreateHandler(config *Config) http.Handler {