diff options
author | Brian Picciano <mediocregopher@gmail.com> | 2022-05-05 19:33:40 -0600 |
---|---|---|
committer | Brian Picciano <mediocregopher@gmail.com> | 2022-05-05 19:33:40 -0600 |
commit | 0277c0276715d326a4bcf2be37d2aec5982078f7 (patch) | |
tree | 8a419665f0c838a5676a8ed6e4a9d23c59059f3d /srv/cmd | |
parent | 24e9541e02be403bd63d71979240377be2ecb122 (diff) |
Get rid of loggerFatalError
Diffstat (limited to 'srv/cmd')
-rw-r--r-- | srv/cmd/mailinglist-cli/main.go | 26 | ||||
-rw-r--r-- | srv/cmd/mediocre-blog/main.go | 19 | ||||
-rwxr-xr-x | srv/cmd/userid-calc-cli/userid-calc-cli | bin | 2711927 -> 0 bytes |
3 files changed, 20 insertions, 25 deletions
diff --git a/srv/cmd/mailinglist-cli/main.go b/srv/cmd/mailinglist-cli/main.go index 4ae47fe..80fde25 100644 --- a/srv/cmd/mailinglist-cli/main.go +++ b/srv/cmd/mailinglist-cli/main.go @@ -3,7 +3,6 @@ package main import ( "context" "errors" - "fmt" "io" "path" @@ -14,10 +13,6 @@ import ( "github.com/tilinna/clock" ) -func loggerFatalErr(ctx context.Context, logger *mlog.Logger, descr string, err error) { - logger.Fatal(ctx, fmt.Sprintf("%s: %v", descr, err)) -} - func main() { ctx := context.Background() cfg := cfg.New() @@ -42,7 +37,7 @@ func main() { defer logger.Info(ctx, "process exiting") if err != nil { - loggerFatalErr(ctx, logger, "initializing", err) + logger.Fatal(ctx, "initializing", err) } clock := clock.Realtime() @@ -57,7 +52,7 @@ func main() { mlStore, err := mailinglist.NewStore(path.Join(*dataDir, "mailinglist.sqlite3")) if err != nil { - loggerFatalErr(ctx, logger, "initializing mailing list storage", err) + logger.Fatal(ctx, "initializing mailing list storage", err) } defer mlStore.Close() @@ -72,13 +67,15 @@ func main() { ctx = mctx.Annotate(ctx, "subCmd", subCmd) switch subCmd { + case "list": + for it := mlStore.GetAll(); ; { email, err := it() if errors.Is(err, io.EOF) { break } else if err != nil { - loggerFatalErr(ctx, logger, "retrieving next email", err) + logger.Fatal(ctx, "retrieving next email", err) } ctx := mctx.Annotate(context.Background(), @@ -94,21 +91,24 @@ func main() { title := cfg.String("title", "", "Title of the post which was published") url := cfg.String("url", "", "URL of the post which was published") - cfg.Init(ctx) + + if err := cfg.Init(ctx); err != nil { + logger.Fatal(ctx, "initializing", err) + } if *title == "" { - logger.Fatal(ctx, "-title is required") + logger.FatalString(ctx, "-title is required") } else if *url == "" { - logger.Fatal(ctx, "-url is required") + logger.FatalString(ctx, "-url is required") } err := ml.Publish(*title, *url) if err != nil { - loggerFatalErr(ctx, logger, "publishing", err) + logger.Fatal(ctx, "publishing", err) } default: - logger.Fatal(ctx, "invalid sub-command, must be list|publish") + logger.FatalString(ctx, "invalid sub-command, must be list|publish") } } diff --git a/srv/cmd/mediocre-blog/main.go b/srv/cmd/mediocre-blog/main.go index 5f473ff..9ac1401 100644 --- a/srv/cmd/mediocre-blog/main.go +++ b/srv/cmd/mediocre-blog/main.go @@ -2,7 +2,6 @@ package main import ( "context" - "fmt" "os" "os/signal" "path" @@ -20,10 +19,6 @@ import ( "github.com/tilinna/clock" ) -func loggerFatalErr(ctx context.Context, logger *mlog.Logger, descr string, err error) { - logger.Fatal(ctx, fmt.Sprintf("%s: %v", descr, err)) -} - func main() { ctx := context.Background() @@ -64,7 +59,7 @@ func main() { defer logger.Info(ctx, "process exiting") if err != nil { - loggerFatalErr(ctx, logger, "initializing", err) + logger.Fatal(ctx, "initializing", err) } ctx = mctx.Annotate(ctx, @@ -95,7 +90,7 @@ func main() { mlStore, err := mailinglist.NewStore(path.Join(*dataDir, "mailinglist.sqlite3")) if err != nil { - loggerFatalErr(ctx, logger, "initializing mailing list storage", err) + logger.Fatal(ctx, "initializing mailing list storage", err) } defer mlStore.Close() @@ -112,7 +107,7 @@ func main() { ) if err != nil { - loggerFatalErr(ctx, logger, "initializing redis pool", err) + logger.Fatal(ctx, "initializing redis pool", err) } defer redis.Close() @@ -123,7 +118,7 @@ func main() { MaxMessages: *chatGlobalRoomMaxMsgs, }) if err != nil { - loggerFatalErr(ctx, logger, "initializing global chat room", err) + logger.Fatal(ctx, "initializing global chat room", err) } defer chatGlobalRoom.Close() @@ -138,20 +133,20 @@ func main() { logger.Info(ctx, "listening") a, err := api.New(apiParams) if err != nil { - loggerFatalErr(ctx, logger, "initializing api", err) + logger.Fatal(ctx, "initializing api", err) } defer func() { shutdownCtx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() if err := a.Shutdown(shutdownCtx); err != nil { - loggerFatalErr(ctx, logger, "shutting down api", err) + logger.Fatal(ctx, "shutting down api", err) } }() // wait - sigCh := make(chan os.Signal) + sigCh := make(chan os.Signal, 1) signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) <-sigCh diff --git a/srv/cmd/userid-calc-cli/userid-calc-cli b/srv/cmd/userid-calc-cli/userid-calc-cli Binary files differdeleted file mode 100755 index ca18cc3..0000000 --- a/srv/cmd/userid-calc-cli/userid-calc-cli +++ /dev/null |