summaryrefslogtreecommitdiff
path: root/srv
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2022-05-05 19:33:40 -0600
committerBrian Picciano <mediocregopher@gmail.com>2022-05-05 19:33:40 -0600
commit0277c0276715d326a4bcf2be37d2aec5982078f7 (patch)
tree8a419665f0c838a5676a8ed6e4a9d23c59059f3d /srv
parent24e9541e02be403bd63d71979240377be2ecb122 (diff)
Get rid of loggerFatalError
Diffstat (limited to 'srv')
-rw-r--r--srv/api/api.go2
-rw-r--r--srv/cmd/mailinglist-cli/main.go26
-rw-r--r--srv/cmd/mediocre-blog/main.go19
-rwxr-xr-xsrv/cmd/userid-calc-cli/userid-calc-clibin2711927 -> 0 bytes
-rw-r--r--srv/go.mod2
-rw-r--r--srv/go.sum2
6 files changed, 24 insertions, 27 deletions
diff --git a/srv/api/api.go b/srv/api/api.go
index adaf6a1..56f33b2 100644
--- a/srv/api/api.go
+++ b/srv/api/api.go
@@ -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)
}
}()
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
deleted file mode 100755
index ca18cc3..0000000
--- a/srv/cmd/userid-calc-cli/userid-calc-cli
+++ /dev/null
Binary files differ
diff --git a/srv/go.mod b/srv/go.mod
index 313e1fe..6a912e2 100644
--- a/srv/go.mod
+++ b/srv/go.mod
@@ -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
diff --git a/srv/go.sum b/srv/go.sum
index 1c51163..77aac2e 100644
--- a/srv/go.sum
+++ b/srv/go.sum
@@ -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=