2022-07-22 19:52:41 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-07-24 02:40:44 +02:00
|
|
|
"context"
|
2022-07-23 00:33:05 +02:00
|
|
|
"log"
|
2022-07-23 00:36:28 +02:00
|
|
|
"os"
|
2022-07-24 02:40:44 +02:00
|
|
|
"os/signal"
|
|
|
|
"sync"
|
|
|
|
"syscall"
|
2022-07-22 19:52:41 +02:00
|
|
|
|
2022-08-10 22:42:23 +02:00
|
|
|
"git.luj0ga.de/franconian/matrix"
|
2022-07-23 00:33:05 +02:00
|
|
|
"git.luj0ga.de/franconian/matrix-pretix/internal/config"
|
2022-07-24 02:40:44 +02:00
|
|
|
"git.luj0ga.de/franconian/matrix-pretix/internal/database"
|
|
|
|
"git.luj0ga.de/franconian/matrix-pretix/internal/pretix"
|
2022-07-22 19:52:41 +02:00
|
|
|
)
|
|
|
|
|
2022-07-23 00:33:05 +02:00
|
|
|
func main() {
|
|
|
|
if len(os.Args) != 2 {
|
|
|
|
log.Fatal("missing config file path")
|
2022-07-22 19:52:41 +02:00
|
|
|
}
|
|
|
|
|
2022-07-23 00:33:05 +02:00
|
|
|
config, err := config.ParseFromFile(os.Args[1])
|
2022-07-22 19:52:41 +02:00
|
|
|
if err != nil {
|
2022-07-23 00:33:05 +02:00
|
|
|
log.Fatal(err)
|
2022-07-22 19:52:41 +02:00
|
|
|
}
|
|
|
|
|
2022-07-24 02:40:44 +02:00
|
|
|
db, err := database.Open(&config.DB)
|
2022-07-22 19:52:41 +02:00
|
|
|
if err != nil {
|
2022-07-23 00:33:05 +02:00
|
|
|
log.Fatal(err)
|
2022-07-22 19:52:41 +02:00
|
|
|
}
|
2022-07-24 02:40:44 +02:00
|
|
|
defer db.Close()
|
|
|
|
|
|
|
|
client, err := matrix.NewClient(&config.Matrix, db)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = client.Login()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = client.Encrypt()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
|
|
defer stop()
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
go func() {
|
|
|
|
wg.Add(1)
|
|
|
|
defer wg.Done()
|
|
|
|
|
|
|
|
<-ctx.Done()
|
|
|
|
|
|
|
|
stop()
|
|
|
|
}()
|
|
|
|
|
2022-07-27 18:04:03 +02:00
|
|
|
go client.Sync(ctx, stop, &wg)
|
2022-07-24 02:40:44 +02:00
|
|
|
|
2022-07-24 21:41:01 +02:00
|
|
|
server := pretix.NewServer(&config.Server, db, client)
|
2022-07-24 02:40:44 +02:00
|
|
|
|
2022-07-24 21:41:01 +02:00
|
|
|
err = server.ListenAndServe(ctx, &wg)
|
2022-07-24 02:40:44 +02:00
|
|
|
if err != nil {
|
|
|
|
stop()
|
|
|
|
wg.Wait()
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
log.Print("done")
|
2022-07-22 19:52:41 +02:00
|
|
|
}
|