MeteorLight/MeteorLight.go
DataHoarder 9ff4d5e9c5
All checks were successful
continuous-integration/drone/push Build is passing
Cleanup API, prefetch queue entries / preload entry for seamless playback
2022-03-05 11:40:06 +01:00

52 lines
864 B
Go

package main
import (
"flag"
"fmt"
"log"
"net/http"
"sync"
"time"
)
func main() {
configPath := flag.String("config", "config.toml", "Config path")
flag.Parse()
config, err := GetConfig(*configPath)
if err != nil {
log.Panic(err)
}
var wg sync.WaitGroup
queue := NewQueue(config)
wg.Add(1)
go func() {
defer wg.Done()
server := http.Server{
Addr: fmt.Sprintf(":%d", config.Radio.Port),
Handler: http.HandlerFunc(queue.HandleRadioRequest),
}
//setup a timeout to prevent slow clients blocking. See https://github.com/golang/go/issues/16100
timeoutListener, err := newListener("tcp", server.Addr, time.Second*5, time.Second*5)
if err != nil {
log.Panic(err)
}
if err = server.Serve(timeoutListener); err != nil {
log.Panic(err)
}
}()
api := NewAPI(config, queue)
api.Wait()
wg.Wait()
queue.Wait()
}