SimpleCloudNotifier/server/cmd/scnserver/main.go

70 lines
1.5 KiB
Go
Raw Normal View History

2022-11-13 19:17:07 +01:00
package main
import (
scn "blackforestbytes.com/simplecloudnotifier"
"blackforestbytes.com/simplecloudnotifier/api"
"blackforestbytes.com/simplecloudnotifier/common"
"blackforestbytes.com/simplecloudnotifier/common/ginext"
"blackforestbytes.com/simplecloudnotifier/db"
"blackforestbytes.com/simplecloudnotifier/google"
2022-11-20 15:40:19 +01:00
"blackforestbytes.com/simplecloudnotifier/jobs"
2022-11-13 19:17:07 +01:00
"blackforestbytes.com/simplecloudnotifier/logic"
2022-11-23 19:32:23 +01:00
"blackforestbytes.com/simplecloudnotifier/push"
2022-11-13 19:17:07 +01:00
"fmt"
"github.com/rs/zerolog/log"
)
var conf = scn.Conf
func main() {
common.Init(conf)
log.Info().Msg(fmt.Sprintf("Starting with config-namespace <%s>", conf.Namespace))
sqlite, err := db.NewDatabase(conf)
2022-11-13 19:17:07 +01:00
if err != nil {
panic(err)
}
app := logic.NewApp(sqlite)
2022-11-18 21:25:40 +01:00
if err := app.Migrate(); err != nil {
2022-11-20 17:19:11 +01:00
log.Fatal().Err(err).Msg("failed to migrate DB")
return
2022-11-18 21:25:40 +01:00
}
2022-11-13 19:17:07 +01:00
ginengine := ginext.NewEngine(conf)
router := api.NewRouter(app)
2022-11-23 19:32:23 +01:00
var nc push.NotificationClient
if conf.DummyFirebase {
nc = push.NewDummy()
2022-11-23 19:32:23 +01:00
} else {
nc, err = push.NewFirebaseConn(conf)
if err != nil {
log.Fatal().Err(err).Msg("failed to init firebase")
return
}
2022-11-20 17:19:11 +01:00
}
2022-11-19 14:57:45 +01:00
var apc google.AndroidPublisherClient
if conf.DummyGoogleAPI {
apc = google.NewDummy()
} else {
apc, err = google.NewAndroidPublisherAPI(conf)
if err != nil {
log.Fatal().Err(err).Msg("failed to init google-api")
return
}
}
2022-11-20 15:40:19 +01:00
jobRetry := jobs.NewDeliveryRetryJob(app)
app.Init(conf, ginengine, nc, apc, []logic.Job{jobRetry})
2022-11-13 19:17:07 +01:00
router.Init(ginengine)
app.Run()
}