diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2025-03-22 07:32:28 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2025-03-22 07:32:28 -0700 |
| commit | 8cc8b98b938b44af8ff6ec2cc173057d19f92920 (patch) | |
| tree | cf8db38031ebdf8b83849294b29fcd528c68208f /roseh.moe.go | |
| parent | d4e3e201e9cfd24229bec3dc7f363724d572a32a (diff) | |
| download | roseh.moe-8cc8b98b938b44af8ff6ec2cc173057d19f92920.tar.zst | |
Use new go 1.22 routing
Diffstat (limited to 'roseh.moe.go')
| -rw-r--r-- | roseh.moe.go | 34 |
1 files changed, 12 insertions, 22 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) - } - }) + 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) - 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) + 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)) } } |
