Adding static file handling

This commit is contained in:
awstin 2025-10-02 22:14:22 -04:00 committed by Awstin
parent 043b1ed7c6
commit c1e8ee336d
2 changed files with 15 additions and 3 deletions

View file

@ -14,6 +14,7 @@ var templates = template.Must(template.ParseFiles("tmpl/edit.html", "tmpl/view.h
var validPath = regexp.MustCompile("^/(edit|save|view)/([a-zA-Z0-9]+)$")
func main() {
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
http.HandleFunc("/view/", makeHandler(viewHandler))
http.HandleFunc("/edit/", makeHandler(editHandler))
http.HandleFunc("/save/", makeHandler(saveHandler))

View file

@ -1,3 +1,14 @@
<h1>{{.Title}}</h1>
<p>[<a href="/edit/{{.Title}}">edit</a>]</p>
<div>{{printf "%s" .Body}}<div>
<!doctype html>
<html lang="en">
<head>
<link href="/static/css/main.css" rel="stylesheet" />
</head>
<body>
<h1>{{.Title}}</h1>
<p>[<a href="/edit/{{.Title}}">edit</a>]</p>
<div>{{printf "%s" .Body}}<div>
</body>
</html>