Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/router/viewTorrentHandler.go
2017-05-06 11:36:37 +03:00

26 lignes
707 o
Go

package router
import (
"github.com/ewhal/nyaa/service/torrent"
"github.com/gorilla/mux"
"html/template"
"net/http"
)
func ViewHandler(w http.ResponseWriter, r *http.Request) {
var templates = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/view.html"))
templates.ParseGlob("templates/_*.html") // common
vars := mux.Vars(r)
id := vars["id"]
torrent, err := torrentService.GetTorrentById(id)
b := torrent.ToJson()
htv := ViewTemplateVariables{b, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
err = templates.ExecuteTemplate(w, "index.html", htv)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}