aboutsummaryrefslogtreecommitdiff
path: root/main.go
blob: d6841f0dc734497f0bf6328ffa895ba77c61d0fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main

import (
	"embed"
	"flag"
	"html/template"
	"net/http"
)

//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()
	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)
}