Compare commits

..

No commits in common. "58e428f6a9cbbb411db7a15be646fddf6b240d5c" and "ba85ab166d2836cd72ce190b9e30c3bd9a36a082" have entirely different histories.

2 changed files with 22 additions and 31 deletions

View File

@ -36,7 +36,7 @@ type Film struct{
Year int Year int
} }
var db_film map[string]any //var db_film []Film
func findURL_in_msg(in_msg string) (_ string,err error){ func findURL_in_msg(in_msg string) (_ string,err error){
@ -200,22 +200,14 @@ func fetch_filmInfo(in_url string) (_ Film, err error){
} }
} }
func hdlr_root(template_renders map[string]struct{Template string;Context *map[string]any}) http.HandlerFunc{ func hdlr_root(template_renders map[string]string) 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.Template) fmt.Println("[srv] template", req.URL.Path, fileName)
url_query := req.URL.Query() err := templates.ExecuteTemplate(resp, fileName, nil)
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)
@ -228,14 +220,14 @@ func hdlr_root(template_renders map[string]struct{Template string;Context *map[s
} }
} }
func templates_register(template_renders map[string]struct{Template string;Context *map[string]any}){ func templates_register(template_renders map[string]string){
for _,i_file := range template_renders{ for _,i_file := range template_renders{
text, err := os.ReadFile("./website/templates/" + i_file.Template) text, err := os.ReadFile("./website/templates/" + i_file)
if(err != nil){ if(err != nil){
panic(err) panic(err)
} }
templates.New(i_file.Template).Parse(string(text)) templates.New(i_file).Parse(string(text))
} }
} }
@ -249,13 +241,10 @@ 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/"+string(len(db_film)-1), http.StatusFound) http.Redirect(resp, req, "/film/view/"+t_film.Title_orig, http.StatusFound)
} }
func main(){ func main(){
@ -282,14 +271,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]struct{Template string;Context *map[string]any} { template_renders := map[string]string {
"/": {"index.html", nil}, "/": "index.html",
"/film/view/": {"index.html", &db_film}, "/film/view/": "index.html",
"/film/edit/": {"index.html", nil}, "/film/edit/": "index.html",
//"/list/view/": {"index.html", nil}, //"/list/view/": "index.html",
//"/list/edit/": {"index.html", nil}, //"/list/edit/": "index.html",
//"/group/view/": {"index.html", nil}, //"/group/view/": "index.html",
//"/group/edit/": {"index.html", nil}, //"/group/edit/": "index.html",
} }
templates_register(template_renders) templates_register(template_renders)

View File

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