summaryrefslogtreecommitdiff
path: root/srv
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2021-08-06 20:34:18 -0600
committerBrian Picciano <mediocregopher@gmail.com>2021-08-06 20:34:18 -0600
commitdce39b836a0fd6e37ab2499c2e0e232572c17ad6 (patch)
tree7d50582a18c19bccd1093268b08f317bb930d130 /srv
parente6d607a2480533f446db40b8572090de5e256333 (diff)
add redis process, put circus in charge of process management
Diffstat (limited to 'srv')
-rw-r--r--srv/cmd/mediocre-blog/main.go42
-rw-r--r--srv/mailinglist/mailer.go9
2 files changed, 33 insertions, 18 deletions
diff --git a/srv/cmd/mediocre-blog/main.go b/srv/cmd/mediocre-blog/main.go
index 66c17ee..0a5f8b7 100644
--- a/srv/cmd/mediocre-blog/main.go
+++ b/srv/cmd/mediocre-blog/main.go
@@ -62,10 +62,6 @@ func main() {
logger.Fatal(ctx, "-static-dir or -static-proxy-url is required")
case *powSecret == "":
logger.Fatal(ctx, "-pow-secret is required")
- case *smtpAddr == "":
- logger.Fatal(ctx, "-ml-smtp-addr is required")
- case *smtpAuthStr == "":
- logger.Fatal(ctx, "-ml-smtp-auth is required")
}
publicURL, err := url.Parse(*publicURLStr)
@@ -87,14 +83,22 @@ func main() {
}
powTarget := uint32(powTargetUint)
- smtpAuthParts := strings.SplitN(*smtpAuthStr, ":", 2)
- if len(smtpAuthParts) < 2 {
- logger.Fatal(ctx, "invalid -ml-smtp-auth")
- }
- smtpAuth := sasl.NewPlainClient("", smtpAuthParts[0], smtpAuthParts[1])
- smtpSendAs := smtpAuthParts[0]
+ var mailerCfg mailinglist.MailerParams
- // initialization
+ if *smtpAddr != "" {
+ mailerCfg.SMTPAddr = *smtpAddr
+ smtpAuthParts := strings.SplitN(*smtpAuthStr, ":", 2)
+ if len(smtpAuthParts) < 2 {
+ logger.Fatal(ctx, "invalid -ml-smtp-auth")
+ }
+ mailerCfg.SMTPAuth = sasl.NewPlainClient("", smtpAuthParts[0], smtpAuthParts[1])
+ mailerCfg.SendAs = smtpAuthParts[0]
+
+ ctx = mctx.Annotate(ctx,
+ "smtpAddr", mailerCfg.SMTPAddr,
+ "smtpSendAs", mailerCfg.SendAs,
+ )
+ }
ctx = mctx.Annotate(ctx,
"publicURL", publicURL.String(),
@@ -102,10 +106,10 @@ func main() {
"listenAddr", *listenAddr,
"dataDir", *dataDir,
"powTarget", fmt.Sprintf("%x", powTarget),
- "smtpAddr", *smtpAddr,
- "smtpSendAs", smtpSendAs,
)
+ // initialization
+
if *staticDir != "" {
ctx = mctx.Annotate(ctx, "staticDir", *staticDir)
} else {
@@ -127,11 +131,13 @@ func main() {
// sugar
requirePow := func(h http.Handler) http.Handler { return requirePowMiddleware(powMgr, h) }
- mailer := mailinglist.NewMailer(mailinglist.MailerParams{
- SMTPAddr: *smtpAddr,
- SMTPAuth: smtpAuth,
- SendAs: smtpSendAs,
- })
+ var mailer mailinglist.Mailer
+ if *smtpAddr == "" {
+ logger.Info(ctx, "-smtp-addr not given, using NullMailer")
+ mailer = mailinglist.NullMailer
+ } else {
+ mailer = mailinglist.NewMailer(mailerCfg)
+ }
mlStore, err := mailinglist.NewStore(path.Join(*dataDir, "mailinglist.sqlite3"))
if err != nil {
diff --git a/srv/mailinglist/mailer.go b/srv/mailinglist/mailer.go
index 81d0b91..12fc398 100644
--- a/srv/mailinglist/mailer.go
+++ b/srv/mailinglist/mailer.go
@@ -10,6 +10,15 @@ type Mailer interface {
Send(to, subject, body string) error
}
+// NullMailer acts as a Mailer but actually just does nothing.
+var NullMailer = nullMailer{}
+
+type nullMailer struct{}
+
+func (nullMailer) Send(to, subject, body string) error {
+ return nil
+}
+
// MailerParams are used to initialize a new Mailer instance
type MailerParams struct {
SMTPAddr string