MeteorLight/MeteorLight.go

54 lines
986 B
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/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()
2022-03-02 17:54:56 +00:00
config, err := GetConfig(*configPath)
2022-03-01 23:31:29 +00:00
if err != nil {
log.Panic(err)
}
var wg sync.WaitGroup
2022-03-02 17:54:56 +00:00
queue := NewQueue(config)
2022-03-01 23:31:29 +00:00
wg.Add(1)
go func() {
defer wg.Done()
server := http.Server{
Addr: fmt.Sprintf("%s:%d", config.Radio.Host, config.Radio.Port),
2022-03-02 17:54:56 +00:00
Handler: http.HandlerFunc(queue.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)
}
}()
api := NewAPI(config, queue)
2022-03-02 17:54:56 +00:00
api.Wait()
2022-03-01 23:31:29 +00:00
wg.Wait()
2022-03-02 17:54:56 +00:00
queue.Wait()
2022-03-01 23:31:29 +00:00
}