aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go41
1 files changed, 29 insertions, 12 deletions
diff --git a/main.go b/main.go
index 2c50720..d6841f0 100644
--- a/main.go
+++ b/main.go
@@ -1,24 +1,41 @@
package main
import (
+ "embed"
"flag"
+ "html/template"
"net/http"
)
-var (
- listen = flag.String("listen", ":8080", "Listen at")
- data = flag.String("data", "data", "Data dir")
-)
+//go:embed static tmpl
+var static embed.FS
func main() {
+ var (
+ listen = flag.String("listen", "localhost:8080", "Listen at")
+ data = flag.String("data", "data", "Data dir")
+ )
flag.Parse()
- http.Handle("/css/", http.FileServer(http.Dir("assets")))
- http.Handle("/fonts/", http.FileServer(http.Dir("assets")))
- http.HandleFunc("/index", indexHandler)
- http.HandleFunc("/view/", viewHandler)
- http.HandleFunc("/edit/", editHandler)
- http.HandleFunc("/del/", delHandler)
- http.HandleFunc("/save/", saveHandler)
- http.HandleFunc("/", homeHandler)
+ wiki := Wiki{Root: *data}
+ http.Handle("GET /static/", http.FileServerFS(static))
+ http.Handle("GET /index", Index{
+ Wiki: wiki,
+ Template: template.Must(template.ParseFS(static, "tmpl/root", "tmpl/index")),
+ })
+ http.Handle("GET /view/{title}", View{
+ Wiki: wiki,
+ Template: template.Must(template.ParseFS(static, "tmpl/root", "tmpl/view")),
+ })
+ http.Handle("GET /edit/{title}", Edit{
+ Wiki: wiki,
+ Template: template.Must(template.ParseFS(static, "tmpl/root", "tmpl/edit")),
+ })
+ http.Handle("POST /save/{title}", Save{
+ Wiki: wiki,
+ })
+ http.Handle("GET /del/{title}", Delete{
+ Wiki: wiki,
+ })
+ http.Handle("GET /", http.RedirectHandler("/view/Home", http.StatusFound))
http.ListenAndServe(*listen, nil)
}