diff --git a/golink.go b/golink.go index ebcd94e..9a8908f 100644 --- a/golink.go +++ b/golink.go @@ -133,6 +133,7 @@ func Run() error { http.HandleFunc("/.export", serveExport) http.HandleFunc("/.help", serveHelp) http.HandleFunc("/.opensearch", serveOpenSearch) + http.HandleFunc("/.all", serveAll) http.Handle("/.static/", http.StripPrefix("/.", http.FileServer(http.FS(embeddedFS)))) if *dev != "" { @@ -193,6 +194,9 @@ var ( // helpTmpl is the template used by the http://go/.help page helpTmpl *template.Template + // allTmpl is the template used by the http://go/.all page + allTmpl *template.Template + // opensearchTmpl is the template used by the http://go/.opensearch page opensearchTmpl *template.Template ) @@ -213,6 +217,7 @@ func init() { detailTmpl = template.Must(template.ParseFS(embeddedFS, "tmpl/base.html", "tmpl/detail.html")) successTmpl = template.Must(template.ParseFS(embeddedFS, "tmpl/base.html", "tmpl/success.html")) helpTmpl = template.Must(template.ParseFS(embeddedFS, "tmpl/base.html", "tmpl/help.html")) + allTmpl = template.Must(template.ParseFS(embeddedFS, "tmpl/base.html", "tmpl/all.html")) opensearchTmpl = template.Must(template.ParseFS(embeddedFS, "tmpl/opensearch.xml")) } @@ -282,6 +287,24 @@ func serveHome(w http.ResponseWriter, short string) { }) } +func serveAll(w http.ResponseWriter, _ *http.Request) { + if err := flushStats(); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + links, err := db.LoadAll() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + sort.Slice(links, func(i, j int) bool { + return links[i].Short < links[j].Short + }) + + allTmpl.Execute(w, links) +} + func serveHelp(w http.ResponseWriter, _ *http.Request) { helpTmpl.Execute(w, nil) } diff --git a/tmpl/all.html b/tmpl/all.html new file mode 100644 index 0000000..836e7e2 --- /dev/null +++ b/tmpl/all.html @@ -0,0 +1,30 @@ +{{ define "main" }} +

All Links

+ + + + + + + + + + + + {{ range . }} + + + + + + + + {{ end }} + +
LinkLongOwnerCreatedLast Edit
+ go/{{ .Short }} + + {{ .Long }}{{ .Owner }}{{ .Created }}{{ .LastEdit }}
+{{ end }}