2022-03-01 23:31:29 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2022-09-03 14:20:40 +00:00
|
|
|
"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"
|
2022-03-03 14:00:34 +00:00
|
|
|
"time"
|
2022-03-01 23:31:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
configPath := flag.String("config", "config.toml", "Config path")
|
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
2022-09-03 14:20:40 +00:00
|
|
|
conf, err := config.GetConfig(*configPath)
|
2022-03-01 23:31:29 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
2022-09-03 14:20:40 +00:00
|
|
|
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{
|
2022-10-02 12:34:13 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-10-02 12:34:13 +00:00
|
|
|
if err = server.ListenAndServe(); err != nil {
|
2022-03-01 23:31:29 +00:00
|
|
|
log.Panic(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2022-09-03 14:20:40 +00:00
|
|
|
apiInstance := api.NewAPI(conf, queueInstance)
|
2022-03-02 17:54:56 +00:00
|
|
|
|
2022-09-03 14:20:40 +00:00
|
|
|
apiInstance.Wait()
|
2022-03-01 23:31:29 +00:00
|
|
|
wg.Wait()
|
2022-09-03 14:20:40 +00:00
|
|
|
queueInstance.Wait()
|
2022-03-01 23:31:29 +00:00
|
|
|
}
|