Get rid of loggerFatalError
This commit is contained in:
parent
24e9541e02
commit
0277c02767
@ -118,7 +118,7 @@ func New(params Params) (API, error) {
|
||||
err := a.srv.Serve(l)
|
||||
if err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
ctx := mctx.Annotate(context.Background(), a.params)
|
||||
params.Logger.Fatal(ctx, fmt.Sprintf("%s: %v", "serving http server", err))
|
||||
params.Logger.Fatal(ctx, "serving http server", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
Binary file not shown.
@ -8,7 +8,7 @@ require (
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/gorilla/websocket v1.4.2 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.8
|
||||
github.com/mediocregopher/mediocre-go-lib/v2 v2.0.0-beta.0
|
||||
github.com/mediocregopher/mediocre-go-lib/v2 v2.0.0-beta.0.0.20220506011745-cbeee71cb1ee
|
||||
github.com/mediocregopher/radix/v4 v4.0.0-beta.1.0.20210726230805-d62fa1b2e3cb // indirect
|
||||
github.com/rubenv/sql-migrate v0.0.0-20210614095031-55d5740dbbcc
|
||||
github.com/stretchr/testify v1.7.0
|
||||
|
@ -108,6 +108,8 @@ github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/mediocregopher/mediocre-go-lib/v2 v2.0.0-beta.0 h1:i9FBkcCaWXxteJ8458AD8dBL2YqSxVlpsHOMWg5N9Dc=
|
||||
github.com/mediocregopher/mediocre-go-lib/v2 v2.0.0-beta.0/go.mod h1:wOZVlnKYvIbkzyCJ3dxy1k40XkirvCd1pisX2O91qoQ=
|
||||
github.com/mediocregopher/mediocre-go-lib/v2 v2.0.0-beta.0.0.20220506011745-cbeee71cb1ee h1:AWRuhgn7iumyhPuxKwed1F1Ri2dXMwxKfp5YIdpnQIY=
|
||||
github.com/mediocregopher/mediocre-go-lib/v2 v2.0.0-beta.0.0.20220506011745-cbeee71cb1ee/go.mod h1:wOZVlnKYvIbkzyCJ3dxy1k40XkirvCd1pisX2O91qoQ=
|
||||
github.com/mediocregopher/radix/v4 v4.0.0-beta.1.0.20210726230805-d62fa1b2e3cb h1:7Y2vAC5q44VJzbBUdxRUEqfz88ySJ/6yXXkpQ+sxke4=
|
||||
github.com/mediocregopher/radix/v4 v4.0.0-beta.1.0.20210726230805-d62fa1b2e3cb/go.mod h1:ajchozX/6ELmydxWeWM6xCFHVpZ4+67LXHOTOVR0nCE=
|
||||
github.com/mitchellh/cli v1.1.2/go.mod h1:6iaV0fGdElS6dPBx0EApTxHrcWvmJphyh2n8YBLPPZ4=
|
||||
|
Loading…
Reference in New Issue
Block a user