package main import ( ihttp "dwelling-radio/internal/http" "dwelling-radio/internal/radio" "flag" "fmt" "log" "net/http" "os" "os/signal" "syscall" "git.arav.su/Arav/httpr" ) var ( listenAddress = flag.String("listen", "/var/run/dwelling-radio/sock", "listen address (ip:port|unix_path)") playlist = flag.String("playlist", "", "path to a playlist") icecastUrl = flag.String("ic-url", "", "URL to an Icecast's status-json.xsl") icecastPlaylistPath = flag.String("ic-playlist", "/var/log/icecast/playlist.log", "path to an Icecast's playlist.log file") songListLen = flag.Int("list-length", 10, "number of songs to show in last N songs table") showVersion = flag.Bool("v", false, "show version") ) var version string func main() { flag.Parse() log.SetFlags(log.Lshortfile) if *showVersion { fmt.Println("dwelling-radio ver.", version, "\nCopyright (c) 2022,2023 Alexander \"Arav\" Andreev ") return } r := httpr.New() lstnrs := radio.NewListeners() djh := ihttp.NewDJHandlers(lstnrs) s := r.Sub("/listener") s.Handler(http.MethodGet, "/", djh.ListenersGet) s.Handler(http.MethodPost, "/", djh.ListenersInc) s.Handler(http.MethodDelete, "/", djh.ListenersDec) s = r.Sub("/playlist") s.Handler(http.MethodGet, "/", http.NotFound) s = r.Sub("/song") s.Handler(http.MethodGet, "/", http.NotFound) srv := ihttp.NewHttpServer(r) if err := srv.Start(*listenAddress); err != nil { log.Fatalln(err) } defer func() { if err := srv.Stop(); err != nil { log.Fatalln(err) } }() doneSignal := make(chan os.Signal, 1) signal.Notify(doneSignal, os.Interrupt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGSEGV) <-doneSignal }