From 17b5ab48ca085cd06e1aef08a8dc4ba41abe92fa Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Fri, 26 May 2023 23:56:00 +0400 Subject: [PATCH] Use httpr instead of httprouter. --- cmd/dwelling-radio/main.go | 40 ++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/cmd/dwelling-radio/main.go b/cmd/dwelling-radio/main.go index d76cd52..a3bcd41 100644 --- a/cmd/dwelling-radio/main.go +++ b/cmd/dwelling-radio/main.go @@ -4,14 +4,18 @@ import ( "dwelling-radio/internal/configuration" "dwelling-radio/internal/http" "dwelling-radio/internal/radio" + "dwelling-radio/web" "errors" "flag" "fmt" "io/fs" "log" + nethttp "net/http" "os" "os/signal" "syscall" + + "git.arav.su/Arav/httpr" ) var version string @@ -51,23 +55,6 @@ func main() { } defer playlistWatcher.Close() - hand := http.NewHandlers(config) - srv := http.NewHttpServer() - - srv.ServeStatic("/assets/*filepath", hand.AssetsFS()) - - srv.GET("/", hand.Index) - - srv.GET("/status", hand.Status) - srv.GET("/lastsong", hand.LastSong) - - srv.GET("/playlist", hand.Playlist) - srv.GET("/filelist", hand.Filelist) - - srv.GET("/robots.txt", http.RobotsTxt) - srv.GET("/sitemap.xml", http.SitemapXML) - srv.GET("/favicon.svg", http.Favicon) - if !*noLiquidsoap { liquid, err := radio.NewLiquidsoap(config.Liquidsoap.ExecPath, config.Liquidsoap.ScriptPath) if err != nil { @@ -83,6 +70,25 @@ func main() { }() } + hand := http.NewHandlers(config) + r := httpr.New() + + r.Handler(nethttp.MethodGet, "/", hand.Index) + + r.Handler(nethttp.MethodGet, "/status", hand.Status) + r.Handler(nethttp.MethodGet, "/lastsong", hand.LastSong) + + r.Handler(nethttp.MethodGet, "/playlist", hand.Playlist) + r.Handler(nethttp.MethodGet, "/filelist", hand.Filelist) + + r.Handler(nethttp.MethodGet, "/robots.txt", http.RobotsTxt) + r.Handler(nethttp.MethodGet, "/sitemap.xml", http.SitemapXML) + r.Handler(nethttp.MethodGet, "/favicon.svg", http.Favicon) + + r.ServeStatic("/assets/*filepath", web.Assets()) + + srv := http.NewHttpServer(r) + if err := srv.Start(config.SplitNetworkAddress()); err != nil { log.Fatalln(err) }