MeteorLight/MeteorLight.go

50 lines
898 B
Go
Raw Permalink 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"
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),
ReadTimeout: time.Second * 5,
2022-03-01 23:31:29 +00:00
}
if err = server.ListenAndServe(); 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
}