Compare commits

...

2 Commits

Author SHA1 Message Date
58e428f6a9 260703_001904 2026-07-03 00:19:04 +02:00
25529fbe5e 260703_000219 2026-07-03 00:02:19 +02:00
2 changed files with 31 additions and 22 deletions

View File

@ -36,7 +36,7 @@ type Film struct{
Year int Year int
} }
//var db_film []Film var db_film map[string]any
func findURL_in_msg(in_msg string) (_ string,err error){ func findURL_in_msg(in_msg string) (_ string,err error){
@ -200,14 +200,22 @@ func fetch_filmInfo(in_url string) (_ Film, err error){
} }
} }
func hdlr_root(template_renders map[string]string) http.HandlerFunc{ func hdlr_root(template_renders map[string]struct{Template string;Context *map[string]any}) http.HandlerFunc{
fSrv := http.FileServer(http.Dir("./website/static")) fSrv := http.FileServer(http.Dir("./website/static"))
return func (resp http.ResponseWriter, req *http.Request){ return func (resp http.ResponseWriter, req *http.Request){
if fileName, ok := template_renders[req.URL.Path]; ok{ if fileName, ok := template_renders[req.URL.Path]; ok{
fmt.Println("[srv] template", req.URL.Path, fileName) fmt.Println("[srv] template", req.URL.Path, fileName.Template)
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 = (*fileName.Context)[url_query_id]
}else{
context = nil
}
err := templates.ExecuteTemplate(resp, fileName.Template, context)
if(err != nil){ if(err != nil){
http.Error(resp, err.Error(), http.StatusInternalServerError) http.Error(resp, err.Error(), http.StatusInternalServerError)
@ -220,14 +228,14 @@ func hdlr_root(template_renders map[string]string) http.HandlerFunc{
} }
} }
func templates_register(template_renders map[string]string){ func templates_register(template_renders map[string]struct{Template string;Context *map[string]any}){
for _,i_file := range template_renders{ for _,i_file := range template_renders{
text, err := os.ReadFile("./website/templates/" + i_file) text, err := os.ReadFile("./website/templates/" + i_file.Template)
if(err != nil){ if(err != nil){
panic(err) panic(err)
} }
templates.New(i_file).Parse(string(text)) templates.New(i_file.Template).Parse(string(text))
} }
} }
@ -241,10 +249,13 @@ func hdlr_film_parseMsg(resp http.ResponseWriter, req *http.Request){
t_url_noRed, _ := resolve_redirs(t_url) t_url_noRed, _ := resolve_redirs(t_url)
fmt.Println(t_url_noRed) fmt.Println(t_url_noRed)
t_film, _ := fetch_filmInfo(t_url_noRed) t_film, _ := fetch_filmInfo(t_url_noRed)
db_film[string(len(db_film)-1)] = t_film
t_json, _ := json.MarshalIndent(t_film, "", " ") t_json, _ := json.MarshalIndent(t_film, "", " ")
fmt.Printf("%+v\n", string(t_json)) 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(){ func main(){
@ -271,14 +282,14 @@ func main(){
//t_json, _ := json.MarshalIndent(t_film, "", " ") //t_json, _ := json.MarshalIndent(t_film, "", " ")
//fmt.Printf("%+v\n", string(t_json)) //fmt.Printf("%+v\n", string(t_json))
template_renders := map[string]string { template_renders := map[string]struct{Template string;Context *map[string]any} {
"/": "index.html", "/": {"index.html", nil},
"/film/view/": "index.html", "/film/view/": {"index.html", &db_film},
"/film/edit/": "index.html", "/film/edit/": {"index.html", nil},
//"/list/view/": "index.html", //"/list/view/": {"index.html", nil},
//"/list/edit/": "index.html", //"/list/edit/": {"index.html", nil},
//"/group/view/": "index.html", //"/group/view/": {"index.html", nil},
//"/group/edit/": "index.html", //"/group/edit/": {"index.html", nil},
} }
templates_register(template_renders) templates_register(template_renders)

View File

@ -13,13 +13,11 @@
</head> </head>
<body> <body>
<input type="text" id="inEl">
<div> <div>
<h1 id="filmInfo_title"></h1> <h1 id="filmInfo_title">{{.Title_orig}}</h1>
<h3 id="filmInfo_year"></h3></br> <h3 id="filmInfo_year">{{.Year}}</h3></br>
<p id="filmInfo_desc"></p></br> <p id="filmInfo_desc">{{.Desc}}</p></br>
<img id="filmInfo_img" width="300" /> <img id="filmInfo_img" width="300" src="{{.Img}}"/>
</div> </div>
</body> </body>
</html> </html>