Added main for a radiodj service.
This commit is contained in:
parent
978a2602d8
commit
8677af243c
71
cmd/dwellin-radiodj/main.go
Normal file
71
cmd/dwellin-radiodj/main.go
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
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 <me@arav.su>")
|
||||||
|
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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user