|
@@ -3,6 +3,7 @@ package web
|
|
|
import (
|
|
import (
|
|
|
"bytes"
|
|
"bytes"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
+ "html/template"
|
|
|
"log"
|
|
"log"
|
|
|
"net/http"
|
|
"net/http"
|
|
|
|
|
|
|
@@ -52,6 +53,23 @@ func getDefault(ctx *context.Context, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+type listLinksHandler struct {
|
|
|
|
|
+ ctx *context.Context
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (h *listLinksHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
+ t := template.New("links")
|
|
|
|
|
+ contents, _ := linksHtmlBytes()
|
|
|
|
|
+ t, err := t.Parse(string(contents))
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ log.Printf("no template")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ routes, _ := h.ctx.GetAll()
|
|
|
|
|
+ t.Execute(w, routes)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// ListenAndServe sets up all web routes, binds the port and handles incoming
|
|
// ListenAndServe sets up all web routes, binds the port and handles incoming
|
|
|
// web requests.
|
|
// web requests.
|
|
|
func ListenAndServe(addr string, admin bool, version string, ctx *context.Context) error {
|
|
func ListenAndServe(addr string, admin bool, version string, ctx *context.Context) error {
|
|
@@ -69,6 +87,7 @@ func ListenAndServe(addr string, admin bool, version string, ctx *context.Contex
|
|
|
mux.HandleFunc("/edit/", func(w http.ResponseWriter, r *http.Request) {
|
|
mux.HandleFunc("/edit/", func(w http.ResponseWriter, r *http.Request) {
|
|
|
serveAsset(w, r, "index.html")
|
|
serveAsset(w, r, "index.html")
|
|
|
})
|
|
})
|
|
|
|
|
+ mux.Handle("/links", &listLinksHandler{ctx})
|
|
|
mux.HandleFunc("/s/", func(w http.ResponseWriter, r *http.Request) {
|
|
mux.HandleFunc("/s/", func(w http.ResponseWriter, r *http.Request) {
|
|
|
serveAsset(w, r, r.URL.Path[len("/s/"):])
|
|
serveAsset(w, r, r.URL.Path[len("/s/"):])
|
|
|
})
|
|
})
|