update render method
This commit is contained in:
parent
1bb57bc94a
commit
26c1f6aa72
@ -39,5 +39,5 @@ func (server *Server) home(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func renderHome(w http.ResponseWriter, data any) {
|
||||
render(w, data, "web/templates/home.html.tmpl", "web/templates/base/header.html.tmpl", "web/templates/base/footer.html.tmpl")
|
||||
renderLayout(w, data, "web/templates/home.html.tmpl")
|
||||
}
|
||||
|
||||
@ -6,7 +6,24 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func render(w http.ResponseWriter, data any, tmpls ...string) {
|
||||
// func render(w http.ResponseWriter, data any, tmpls ...string) {
|
||||
// t, err := template.ParseFiles(tmpls...)
|
||||
// if err != nil {
|
||||
// log.Printf("template parse: %v", err)
|
||||
// w.WriteHeader(http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
|
||||
// err = t.Execute(w, data)
|
||||
// if err != nil {
|
||||
// log.Printf("template execute: %v", err)
|
||||
// w.WriteHeader(http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
|
||||
func renderLayout(w http.ResponseWriter, data any, tmpls ...string) {
|
||||
tmpls = append(tmpls, "web/templates/base/header.html.tmpl", "web/templates/base/footer.html.tmpl")
|
||||
t, err := template.ParseFiles(tmpls...)
|
||||
if err != nil {
|
||||
log.Printf("template parse: %v", err)
|
||||
|
||||
@ -17,7 +17,7 @@ func (server *Server) registerView(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func renderRegister(w http.ResponseWriter, data any) {
|
||||
render(w, data, "web/templates/user/register.html.tmpl", "web/templates/base/header.html.tmpl", "web/templates/base/footer.html.tmpl")
|
||||
renderLayout(w, data, "web/templates/user/register.html.tmpl")
|
||||
}
|
||||
|
||||
// type userResponse struct {
|
||||
@ -127,7 +127,7 @@ func (server *Server) loginView(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func renderLogin(w http.ResponseWriter, data any) {
|
||||
render(w, data, "web/templates/user/login.html.tmpl", "web/templates/base/header.html.tmpl", "web/templates/base/footer.html.tmpl")
|
||||
renderLayout(w, data, "web/templates/user/login.html.tmpl")
|
||||
}
|
||||
|
||||
// type loginUserResponse struct {
|
||||
|
||||
@ -32,7 +32,7 @@ func (server *Server) play(w http.ResponseWriter, r *http.Request) {
|
||||
if err == nil {
|
||||
data.Authorize = *auth
|
||||
}
|
||||
render(w, data, "web/templates/video/play.html.tmpl", "web/templates/base/header.html.tmpl", "web/templates/base/footer.html.tmpl")
|
||||
renderLayout(w, data, "web/templates/video/play.html.tmpl")
|
||||
}
|
||||
|
||||
/*
|
||||
@ -111,7 +111,7 @@ func (server *Server) videosView(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
render(w, data, "web/templates/me/videos.html.tmpl", "web/templates/base/header.html.tmpl", "web/templates/base/footer.html.tmpl")
|
||||
renderLayout(w, data, "web/templates/me/videos.html.tmpl")
|
||||
}
|
||||
|
||||
func (server *Server) createVideoView(w http.ResponseWriter, r *http.Request) {
|
||||
@ -134,7 +134,7 @@ func (server *Server) createVideoView(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func renderCreateVideo(w http.ResponseWriter, data any) {
|
||||
render(w, data, "web/templates/video/edit.html.tmpl", "web/templates/base/header.html.tmpl", "web/templates/base/footer.html.tmpl")
|
||||
renderLayout(w, data, "web/templates/video/edit.html.tmpl")
|
||||
}
|
||||
|
||||
type videoCreateResp struct {
|
||||
@ -261,7 +261,7 @@ func (server *Server) transferView(w http.ResponseWriter, r *http.Request) {
|
||||
if err == nil {
|
||||
data.Authorize = *u
|
||||
}
|
||||
render(w, data, "web/templates/video/transfer.html.tmpl", "web/templates/base/header.html.tmpl", "web/templates/base/footer.html.tmpl")
|
||||
renderLayout(w, data, "web/templates/video/transfer.html.tmpl")
|
||||
}
|
||||
|
||||
func (server *Server) transfer(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user