x/http/templates.go
Colin Henry 6e60671cfd WIP
2020-05-20 23:18:58 -07:00

24 lines
535 B
Go
Executable File

package http
import (
"net/http"
"os"
"path/filepath"
"text/template"
)
func RenderTemplate(w http.ResponseWriter, tmpl string, data interface{}) {
cwd, _ := os.Getwd()
// t, err := template.ParseFiles(filepath.Join(cwd, "./routes/"+tmpl+"/"+tmpl+".html"))
t, err := template.ParseFiles(filepath.Join(cwd, "./"+tmpl+".html"))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = t.Execute(w, data)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}