1
0

Use httpr instead of httprouter.

This commit is contained in:
Alexander Andreev 2023-05-26 23:56:00 +04:00
parent 8b439bbd5a
commit 17b5ab48ca
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -4,14 +4,18 @@ import (
"dwelling-radio/internal/configuration" "dwelling-radio/internal/configuration"
"dwelling-radio/internal/http" "dwelling-radio/internal/http"
"dwelling-radio/internal/radio" "dwelling-radio/internal/radio"
"dwelling-radio/web"
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"io/fs" "io/fs"
"log" "log"
nethttp "net/http"
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
"git.arav.su/Arav/httpr"
) )
var version string var version string
@ -51,23 +55,6 @@ func main() {
} }
defer playlistWatcher.Close() 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 { if !*noLiquidsoap {
liquid, err := radio.NewLiquidsoap(config.Liquidsoap.ExecPath, config.Liquidsoap.ScriptPath) liquid, err := radio.NewLiquidsoap(config.Liquidsoap.ExecPath, config.Liquidsoap.ScriptPath)
if err != nil { 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 { if err := srv.Start(config.SplitNetworkAddress()); err != nil {
log.Fatalln(err) log.Fatalln(err)
} }