DataHoarder
b8610799c8
All checks were successful
continuous-integration/drone/push Build is passing
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
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"
|
|
"log"
|
|
"net/http"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
configPath := flag.String("config", "config.toml", "Config path")
|
|
|
|
flag.Parse()
|
|
|
|
conf, err := config.GetConfig(*configPath)
|
|
if err != nil {
|
|
log.Panic(err)
|
|
}
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
queueInstance := queue.NewQueue(conf)
|
|
|
|
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),
|
|
}
|
|
server.SetKeepAlivesEnabled(false)
|
|
|
|
//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 {
|
|
log.Panic(err)
|
|
}
|
|
}()
|
|
|
|
apiInstance := api.NewAPI(conf, queueInstance)
|
|
|
|
apiInstance.Wait()
|
|
wg.Wait()
|
|
queueInstance.Wait()
|
|
}
|