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