24 lines
535 B
Go
Executable File
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)
|
|
}
|
|
}
|