diff --git a/bin/README.md b/bin/README.md index 33b393e..da29603 100644 --- a/bin/README.md +++ b/bin/README.md @@ -11,6 +11,9 @@ go build -o xtemplate # build from repo root go build -o xtemplate ./bin + +# build with sqlite3 driver and json extensions +GOFLAGS='-tags="sqlite_json"' CGO_ENABLED=1 go build -o xtemplate ``` ### Usage diff --git a/serve.go b/serve.go index 59bb58d..5a4a3a0 100644 --- a/serve.go +++ b/serve.go @@ -75,8 +75,10 @@ func (t *XTemplate) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } log.Info("error executing template", "error", err) - if dberr := tx.Rollback(); dberr != nil { - log.Info("failed to roll back transaction", "error", err) + if tx != nil { + if dberr := tx.Rollback(); dberr != nil { + log.Info("failed to roll back transaction", "error", dberr) + } } http.Error(w, "failed to render response", http.StatusInternalServerError) return diff --git a/templates.go b/templates.go index bb016ad..44ef41f 100644 --- a/templates.go +++ b/templates.go @@ -92,12 +92,12 @@ func (t *XTemplate) Reload() error { } // add the route handler template if !strings.HasPrefix(filepath.Base(path_), "_") { - path_ = strings.TrimSuffix(path_, filepath.Ext(path_)) - if path.Base(path_) == "index" { - path_ = path.Dir(path_) + routePath := strings.TrimSuffix(path_, filepath.Ext(path_)) + if path.Base(routePath) == "index" { + routePath = path.Dir(routePath) } - route := "GET " + path_ - log.Debug("adding filename route template", "route", route, "path", path_) + route := "GET " + routePath + log.Debug("adding filename route template", "route", route, "routePath", routePath, "path", path_) _, err = templates.AddParseTree(route, newtemplates[path_]) if err != nil { return fmt.Errorf("could not add parse tree from '%s': %v", path_, err)