260702_023719
This commit is contained in:
parent
a2d00a212d
commit
01bb14e465
53
moira_db.go
53
moira_db.go
@ -1,8 +1,57 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
//"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
//"regexp"
|
||||
//"strings"
|
||||
//"maps"
|
||||
//"slices"
|
||||
)
|
||||
|
||||
|
||||
var templates *template.Template = template.New("")
|
||||
|
||||
|
||||
func hdlr_renderHTML(in_leaderPath string, in_fileName string) http.HandlerFunc{
|
||||
return func (resp http.ResponseWriter, req *http.Request){
|
||||
err := templates.ExecuteTemplate(resp, in_fileName, nil) // resp, in_fileName, contextObj)
|
||||
|
||||
if(err != nil){
|
||||
http.Error(resp, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main(){
|
||||
fmt.Println("Welcome to moira_db!");
|
||||
http.Handle("/", http.FileServer(http.Dir("./website/static")))
|
||||
|
||||
template_renders := map[string]string {
|
||||
"/film/view/": "film/index.html",
|
||||
"/film/edit/": "index.html",
|
||||
"/list/view/": "index.html",
|
||||
"/list/edit/": "index.html",
|
||||
"/group/view/": "index.html",
|
||||
"/group/edit/": "index.html",
|
||||
}
|
||||
|
||||
for _,i_file := range template_renders{
|
||||
text, err := os.ReadFile("./website/templates/" + i_file)
|
||||
if(err != nil){
|
||||
panic(err)
|
||||
}
|
||||
|
||||
templates.New(i_file).Parse(string(text))
|
||||
}
|
||||
|
||||
for i_path,i_file := range template_renders{
|
||||
http.HandleFunc(i_path, hdlr_renderHTML(i_path, i_file))
|
||||
}
|
||||
|
||||
|
||||
//fmt.Println("Welcome to moira_db!");
|
||||
log.Fatal(http.ListenAndServe(":8000", nil))
|
||||
}
|
||||
|
||||
1
website/static/mani.json
Normal file
1
website/static/mani.json
Normal file
@ -0,0 +1 @@
|
||||
aabbcc
|
||||
1
website/static/somefile.txt
Normal file
1
website/static/somefile.txt
Normal file
@ -0,0 +1 @@
|
||||
dis ys desd
|
||||
1
website/templates/film/index.html
Normal file
1
website/templates/film/index.html
Normal file
@ -0,0 +1 @@
|
||||
aaaabb
|
||||
7
website/templates/index.html
Normal file
7
website/templates/index.html
Normal file
@ -0,0 +1,7 @@
|
||||
<h1 id="abc">Ttesttt</h1>
|
||||
<h1>Ttesttt</h1>
|
||||
<script>
|
||||
window.onload = () => {
|
||||
document.getElementById("abc").innerHTML = window.location.pathname.split("/").at(-1);
|
||||
};
|
||||
</script>
|
||||
Loading…
x
Reference in New Issue
Block a user