smtp2shoutrrr/cmd/smtp2shoutrrr/main.go

55 lines
1.3 KiB
Go

package main
import (
"context"
"log/slog"
"os"
"codeberg.org/fmartingr/smtp2shoutrrr"
"git.nakama.town/fmartingr/gotoolkit/encoding"
"git.nakama.town/fmartingr/gotoolkit/model"
"git.nakama.town/fmartingr/gotoolkit/service"
_ "golang.org/x/crypto/x509roots/fallback"
)
func main() {
var config *smtp2shoutrrr.Config
configPath := "config.toml"
f, err := os.Open(configPath)
if err != nil {
slog.Error("Error opening config file", slog.String("err", err.Error()), slog.String("path", configPath))
return
}
enc := encoding.NewTOMLEncoding()
if err := enc.DecodeReader(f, &config); err != nil {
slog.Error("Error decoding config file", slog.String("err", err.Error()), slog.String("path", configPath))
return
}
config.SetDefaults()
slog.Info("config loaded", slog.Int("recipients", len(config.Recipients)))
ctx := context.Background()
smtpServer := smtp2shoutrrr.NewSMTPServer(config)
svc, err := service.NewService([]model.Server{
smtpServer,
})
if err != nil {
slog.Error("Error creating service:", slog.String("err", err.Error()))
return
}
if err := svc.Start(ctx); err != nil {
slog.Error("Error starting service:", slog.String("err", err.Error()))
return
}
if err := svc.WaitStop(ctx); err != nil {
slog.Error("Error waiting for service interruption:", slog.String("err", err.Error()))
}
}