serverHandler returns the main http.Handler for serving all requests.
()
| 410 | |
| 411 | // serverHandler returns the main http.Handler for serving all requests. |
| 412 | func serveHandler() http.Handler { |
| 413 | mux := http.NewServeMux() |
| 414 | mux.HandleFunc("/.detail/", serveDetail) |
| 415 | mux.HandleFunc("/.export", serveExport) |
| 416 | mux.HandleFunc("/.help", serveHelp) |
| 417 | mux.HandleFunc("/.opensearch", serveOpenSearch) |
| 418 | mux.HandleFunc("/.all", serveAll) |
| 419 | mux.HandleFunc("/.delete/", serveDelete) |
| 420 | mux.Handle("/.static/", http.StripPrefix("/.", http.FileServer(http.FS(embeddedFS)))) |
| 421 | |
| 422 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 423 | // all internal URLs begin with a leading "."; any other URL is treated as a go link. |
| 424 | // Serve go links directly without passing through the ServeMux, |
| 425 | // which sometimes modifies the request URL path, which we don't want. |
| 426 | if !strings.HasPrefix(r.URL.Path, "/.") { |
| 427 | serveGo(w, r) |
| 428 | return |
| 429 | } |
| 430 | mux.ServeHTTP(w, r) |
| 431 | }) |
| 432 | } |
| 433 | |
| 434 | func serveHome(w http.ResponseWriter, r *http.Request, short string) { |
| 435 | var clicks []visitData |