Compare commits
2 Commits
ba85ab166d
...
58e428f6a9
| Author | SHA1 | Date | |
|---|---|---|---|
| 58e428f6a9 | |||
| 25529fbe5e |
43
moira_db.go
43
moira_db.go
@ -36,7 +36,7 @@ type Film struct{
|
||||
|
||||
Year int
|
||||
}
|
||||
//var db_film []Film
|
||||
var db_film map[string]any
|
||||
|
||||
|
||||
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"))
|
||||
|
||||
return func (resp http.ResponseWriter, req *http.Request){
|
||||
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){
|
||||
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{
|
||||
text, err := os.ReadFile("./website/templates/" + i_file)
|
||||
text, err := os.ReadFile("./website/templates/" + i_file.Template)
|
||||
if(err != nil){
|
||||
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)
|
||||
fmt.Println(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, "", " ")
|
||||
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(){
|
||||
@ -271,14 +282,14 @@ func main(){
|
||||
//t_json, _ := json.MarshalIndent(t_film, "", " ")
|
||||
//fmt.Printf("%+v\n", string(t_json))
|
||||
|
||||
template_renders := map[string]string {
|
||||
"/": "index.html",
|
||||
"/film/view/": "index.html",
|
||||
"/film/edit/": "index.html",
|
||||
//"/list/view/": "index.html",
|
||||
//"/list/edit/": "index.html",
|
||||
//"/group/view/": "index.html",
|
||||
//"/group/edit/": "index.html",
|
||||
template_renders := map[string]struct{Template string;Context *map[string]any} {
|
||||
"/": {"index.html", nil},
|
||||
"/film/view/": {"index.html", &db_film},
|
||||
"/film/edit/": {"index.html", nil},
|
||||
//"/list/view/": {"index.html", nil},
|
||||
//"/list/edit/": {"index.html", nil},
|
||||
//"/group/view/": {"index.html", nil},
|
||||
//"/group/edit/": {"index.html", nil},
|
||||
}
|
||||
|
||||
templates_register(template_renders)
|
||||
|
||||
@ -13,13 +13,11 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<input type="text" id="inEl">
|
||||
|
||||
<div>
|
||||
<h1 id="filmInfo_title"></h1>
|
||||
<h3 id="filmInfo_year"></h3></br>
|
||||
<p id="filmInfo_desc"></p></br>
|
||||
<img id="filmInfo_img" width="300" />
|
||||
<h1 id="filmInfo_title">{{.Title_orig}}</h1>
|
||||
<h3 id="filmInfo_year">{{.Year}}</h3></br>
|
||||
<p id="filmInfo_desc">{{.Desc}}</p></br>
|
||||
<img id="filmInfo_img" width="300" src="{{.Img}}"/>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user