diff --git a/moira_db.go b/moira_db.go index bcacb23..c506c0c 100644 --- a/moira_db.go +++ b/moira_db.go @@ -36,7 +36,7 @@ type Film struct{ Year int } -//var db_film []Film +var db_film []Film func findURL_in_msg(in_msg string) (_ string,err error){ @@ -207,7 +207,15 @@ func hdlr_root(template_renders map[string]string) http.HandlerFunc{ if fileName, ok := template_renders[req.URL.Path]; ok{ fmt.Println("[srv] template", req.URL.Path, fileName) - err := templates.ExecuteTemplate(resp, fileName, nil) + url_query := req.URL.Query() + url_query_id := url_query.Get("id") + var context any + if(url_query_id != ""){ + context = db_film[int(url_query_id)] + }else{ + context = nil + } + err := templates.ExecuteTemplate(resp, fileName, context) if(err != nil){ http.Error(resp, err.Error(), http.StatusInternalServerError) @@ -241,10 +249,13 @@ func hdlr_film_parseMsg(resp http.ResponseWriter, req *http.Request){ t_url_noRed, _ := resolve_redirs(t_url) fmt.Println(t_url_noRed) t_film, _ := fetch_filmInfo(t_url_noRed) + + db_film = append(db_film, t_film) + t_json, _ := json.MarshalIndent(t_film, "", " ") fmt.Printf("%+v\n", string(t_json)) - http.Redirect(resp, req, "/film/view/"+t_film.Title_orig, http.StatusFound) + http.Redirect(resp, req, "/film/view/"+string(len(db_film)-1), http.StatusFound) } func main(){ diff --git a/website/templates/film/view/index.html b/website/templates/film/view/index.html index 94cdf4a..c0708d4 100644 --- a/website/templates/film/view/index.html +++ b/website/templates/film/view/index.html @@ -13,13 +13,11 @@ - -
-

-


-


- +

{{.Title_orig}}

+

{{.Year}}


+

{{.Desc}}


+