From a10a604018d0cb07babfe218d9fb2e00e1c8ae3b Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 7 May 2022 13:17:18 -0600 Subject: Refactor how data dir is initialized --- srv/src/cmd/mailinglist-cli/main.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'srv/src/cmd/mailinglist-cli') diff --git a/srv/src/cmd/mailinglist-cli/main.go b/srv/src/cmd/mailinglist-cli/main.go index c3207df..c090f41 100644 --- a/srv/src/cmd/mailinglist-cli/main.go +++ b/srv/src/cmd/mailinglist-cli/main.go @@ -4,9 +4,9 @@ import ( "context" "errors" "io" - "path" "github.com/mediocregopher/blog.mediocregopher.com/srv/cfg" + cfgpkg "github.com/mediocregopher/blog.mediocregopher.com/srv/cfg" "github.com/mediocregopher/blog.mediocregopher.com/srv/mailinglist" "github.com/mediocregopher/mediocre-go-lib/v2/mctx" "github.com/mediocregopher/mediocre-go-lib/v2/mlog" @@ -17,11 +17,12 @@ func main() { ctx := context.Background() - cfg := cfg.New(cfg.Params{ - EnvPrefix: "MEDIOCRE_BLOG", - }) + cfg := cfgpkg.NewBlogCfg(cfg.Params{}) - dataDir := cfg.String("data-dir", ".", "Directory to use for long term storage") + var dataDir cfgpkg.DataDir + dataDir.SetupCfg(cfg) + defer dataDir.Close() + ctx = mctx.WithAnnotator(ctx, &dataDir) var mailerParams mailinglist.MailerParams mailerParams.SetupCfg(cfg) @@ -54,10 +55,7 @@ func main() { mailer = mailinglist.NewMailer(mailerParams) } - mailingListDBFile := path.Join(*dataDir, "mailinglist.sqlite3") - ctx = mctx.Annotate(ctx, "mailingListDBFile", mailingListDBFile) - - mlStore, err := mailinglist.NewStore(mailingListDBFile) + mlStore, err := mailinglist.NewStore(dataDir) if err != nil { logger.Fatal(ctx, "initializing mailing list storage", err) } -- cgit v1.2.3