MeteorLight/MeteorLight.go

57 lines
1.2 KiB
Go
Raw Normal View History

2022-03-01 23:31:29 +00:00
package main
import (
"flag"
"fmt"
"git.gammaspectra.live/S.O.N.G/MeteorLight/api"
"git.gammaspectra.live/S.O.N.G/MeteorLight/config"
"git.gammaspectra.live/S.O.N.G/MeteorLight/queue"
"git.gammaspectra.live/S.O.N.G/MeteorLight/util"
2022-03-01 23:31:29 +00:00
"log"
"net/http"
"sync"
"time"
2022-03-01 23:31:29 +00:00
)
func main() {
configPath := flag.String("config", "config.toml", "Config path")
flag.Parse()
conf, err := config.GetConfig(*configPath)
2022-03-01 23:31:29 +00:00
if err != nil {
log.Panic(err)
}
var wg sync.WaitGroup
queueInstance := queue.NewQueue(conf)
2022-03-02 17:54:56 +00:00
2022-03-01 23:31:29 +00:00
wg.Add(1)
go func() {
defer wg.Done()
server := http.Server{
Addr: fmt.Sprintf("%s:%d", conf.Radio.Host, conf.Radio.Port),
Handler: http.HandlerFunc(queueInstance.HandleRadioRequest),
2022-03-01 23:31:29 +00:00
}
server.SetKeepAlivesEnabled(false)
2022-03-01 23:31:29 +00:00
//setup a timeout to prevent slow clients blocking. See https://github.com/golang/go/issues/16100
timeoutListener, err := util.NewTimeoutListener("tcp", server.Addr, time.Second*15, time.Second*15)
if err != nil {
log.Panic(err)
}
if err = server.Serve(timeoutListener); err != nil {
2022-03-01 23:31:29 +00:00
log.Panic(err)
}
}()
apiInstance := api.NewAPI(conf, queueInstance)
2022-03-02 17:54:56 +00:00
apiInstance.Wait()
2022-03-01 23:31:29 +00:00
wg.Wait()
queueInstance.Wait()
2022-03-01 23:31:29 +00:00
}