diff options
| author | 2025-10-25 23:25:31 +0700 | |
|---|---|---|
| committer | 2025-10-25 23:25:31 +0700 | |
| commit | dd69b45d3a41be2b5c38892c3b107770a0f859f2 (patch) | |
| tree | d2b6ed2bd645eef448f987e57b97ff918909ea48 /main.go | |
| parent | 69b868a7655a25c82ce4a2bd444812be69c8b998 (diff) | |
| parent | 629e275e5270ed146f9cd6dba25383cf80022909 (diff) | |
| download | web-0.11.0.tar.gz web-0.11.0.zip | |
v0.11.0 (#17)v0.11.0
- [feat: send new blog posts to
subscribers](https://github.com/SayaAndy/saya-today-web/commit/adcd8cf82f7ec4027701643c545b1f27a7cfc221)
- [feat: email
linking](https://github.com/SayaAndy/saya-today-web/commit/0d261d2f7d080b610f50102576073e334a89e8cb)
- [feat: subscription
settings](https://github.com/SayaAndy/saya-today-web/commit/4b2da2abbc7376ce0de71a00b18b7091b00dbcd1)
- [feat: allow to unsubscribe from an
email](https://github.com/SayaAndy/saya-today-web/commit/df7a0ae1c0fc177cba2eae8cc73fe21d2afdd229)
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -11,8 +11,10 @@ import ( "github.com/SayaAndy/saya-today-web/config" "github.com/SayaAndy/saya-today-web/internal/b2" + "github.com/SayaAndy/saya-today-web/internal/blogtrigger" "github.com/SayaAndy/saya-today-web/internal/factgiver" "github.com/SayaAndy/saya-today-web/internal/glightbox" + "github.com/SayaAndy/saya-today-web/internal/mailer" "github.com/SayaAndy/saya-today-web/internal/router" "github.com/SayaAndy/saya-today-web/internal/tailwind" "github.com/SayaAndy/saya-today-web/locale" @@ -144,9 +146,31 @@ func main() { os.Exit(1) } + router.Mailer, err = mailer.NewMailer(db, cfg.Mail.ClientHost, cfg.Mail.MailHost, + cfg.Mail.PublicName, cfg.Mail.MailAddress, cfg.Mail.Username, cfg.Mail.Password, []byte(cfg.Mail.Salt), localization) + if err != nil { + slog.Error("fail to initialize mailer", slog.String("error", err.Error())) + os.Exit(1) + } + + router.BlogTrigger, err = blogtrigger.NewBlogTriggerScheduler(b2Client, cfg.AvailableLanguages, cfg.Mail.Trigger.OnNewPost, func(bp []*b2.BlogPage) error { + for _, post := range bp { + if err := router.Mailer.NewPost(post); err != nil { + return err + } + } + return nil + }) + if err != nil { + slog.Error("fail to initialize blog trigger", slog.String("error", err.Error())) + os.Exit(1) + } + app.Get("/", router.Api_V1_GeneralPage(localization, availableLanguages)) app.Get("/:lang<len(2)>", router.Api_V1_GeneralPage(localization, availableLanguages)) app.Get("/:lang/map", router.Lang_Map(localization, availableLanguages, b2Client)) + app.Get("/:lang/user", router.Api_V1_GeneralPage(localization, availableLanguages)) + app.Get("/:lang/user/unsubscribe", router.Lang_User_Unsubscribe(localization, availableLanguages)) app.Get("/:lang/blog", router.Api_V1_GeneralPage(localization, availableLanguages)) app.Get("/:lang/blog/:title", router.Api_V1_GeneralPage(localization, availableLanguages)) @@ -159,6 +183,10 @@ func main() { app.Get("/api/v1/general-page/footer", router.Api_V1_GeneralPage_Footer(localization, availableLanguages)) app.Get("/api/v1/general-page/top-embeds", router.Api_V1_GeneralPage_TopEmbeds(localization, availableLanguages)) app.Get("/api/v1/general-page/bottom-embeds", router.Api_V1_GeneralPage_BottomEmbeds(localization, availableLanguages, b2Client)) + app.Post("/api/v1/email/send-verification-code", router.Api_V1_Email_SendVerificationCode(localization)) + app.Post("/api/v1/email/verify", router.Api_V1_Email_Verify(localization)) + app.Get("/api/v1/email/is-in-verification", router.Api_V1_Email_IsInVerification(localization)) + app.Put("/api/v1/subs", router.Api_V1_Subs_Put(localization)) app.Static("/", "./static") @@ -174,6 +202,9 @@ func main() { <-sigChan slog.Info("gracefully shutting down...") + if err = router.BlogTrigger.Close(); err != nil { + slog.Error("fail to shutdown blog trigger scheduler", slog.String("error", err.Error())) + } if err = app.Shutdown(); err != nil { slog.Error("fail to shutdown fiber server", slog.String("error", err.Error())) } |