From 8cc8b98b938b44af8ff6ec2cc173057d19f92920 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sat, 22 Mar 2025 07:32:28 -0700 Subject: Use new go 1.22 routing --- roseh.moe.go | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/roseh.moe.go b/roseh.moe.go index df86f2d..8ca8872 100644 --- a/roseh.moe.go +++ b/roseh.moe.go @@ -95,34 +95,24 @@ func favicon(w http.ResponseWriter, r *http.Request) { func main() { flag.Parse() - mux := http.NewServeMux() - mux.HandleFunc("/pong", pong) + http.HandleFunc("GET /pong", pong) jellyfinURL, err := url.Parse("http://localhost:8096") if err != nil { log.Fatalf("Jellyfin URL: %s", err) } - mux.Handle("/cinema/", httputil.NewSingleHostReverseProxy(jellyfinURL)) - mux.HandleFunc("/static/", static) - mux.HandleFunc("/favicon.ico", favicon) - mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/" { - index(w, r) - } else { - notFound(w, r) - } - }) - - httpServer := http.Server{ - Addr: fmt.Sprintf(":%d", *port), - Handler: mux, - ReadTimeout: 5 * time.Second, - WriteTimeout: 5 * time.Second, - } - - log.Printf("Listening on %q", httpServer.Addr) + http.Handle("/cinema/", httputil.NewSingleHostReverseProxy(jellyfinURL)) + http.HandleFunc("GET /static/", static) + http.HandleFunc("GET /favicon.ico", favicon) + http.HandleFunc("GET /{$}", index) + notFoundMux := http.NewServeMux() + notFoundMux.HandleFunc("GET /", notFound) + http.Handle("/", notFoundMux) + + addr := fmt.Sprintf(":%d", *port) + log.Printf("Listening on %q", addr) if *https { - log.Fatal(httpServer.ListenAndServeTLS("/var/lib/acme/roseh.moe/cert.pem", "/var/lib/acme/roseh.moe/key.pem")) + log.Fatal(http.ListenAndServeTLS(addr, "/var/lib/acme/roseh.moe/cert.pem", "/var/lib/acme/roseh.moe/key.pem", nil)) } else { - log.Fatal(httpServer.ListenAndServe()) + log.Fatal(http.ListenAndServe(addr, nil)) } } -- cgit v1.3.1