diff options
| author | Xe Iaso <me@xeiaso.net> | 2023-07-26 14:24:54 -0400 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2023-07-26 14:24:54 -0400 |
| commit | 319d0244c9418a02c4abeaeec79054320807fd7f (patch) | |
| tree | a79858504c27b032084e2bc8080d484188b20029 /cmd | |
| parent | bf25ec3d842f814f0d146567d0a1aeba7d9382dd (diff) | |
| download | x-319d0244c9418a02c4abeaeec79054320807fd7f.tar.xz x-319d0244c9418a02c4abeaeec79054320807fd7f.zip | |
fix builds, start to use internal slog package
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/apeirophobia/main.go | 10 | ||||
| -rw-r--r-- | cmd/marabot/main.go | 30 | ||||
| -rw-r--r-- | cmd/sanguisuga/main.go | 14 |
3 files changed, 16 insertions, 38 deletions
diff --git a/cmd/apeirophobia/main.go b/cmd/apeirophobia/main.go index 8391268..5ad1792 100644 --- a/cmd/apeirophobia/main.go +++ b/cmd/apeirophobia/main.go @@ -24,7 +24,6 @@ var ( dbLoc = flag.String("db-loc", "./data.db", "") openAIModel = flag.String("openai-model", "gpt-3.5-turbo", "OpenAI model to use") openAIToken = flag.String("openai-token", "", "OpenAI API token") - slogLevel = flag.String("slog-level", "INFO", "log level") tsHostname = flag.String("ts-hostname", "apeirophobia", "hostname to use on the tailnet") tsDir = flag.String("ts-dir", "", "directory to store Tailscale state") @@ -42,15 +41,6 @@ func main() { internal.HandleStartup() hostinfo.SetApp("within.website/x/cmd/apeirophobia") - var programLevel slog.Level - if err := (&programLevel).UnmarshalText([]byte(*slogLevel)); err != nil { - fmt.Fprintf(os.Stderr, "invalid log level %s: %v, using info\n", *slogLevel, err) - programLevel = slog.LevelInfo - } - - h := slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: programLevel}) - slog.SetDefault(slog.New(h)) - slog.Debug("starting up", "hostname", *tsHostname) http.DefaultServeMux.Handle("/static/", http.FileServer(http.FS(staticFiles))) diff --git a/cmd/marabot/main.go b/cmd/marabot/main.go index 0092955..ae5b99a 100644 --- a/cmd/marabot/main.go +++ b/cmd/marabot/main.go @@ -178,12 +178,12 @@ func (mr *MaraRevolt) PreprocessLinks(data [][3]string) { } func (mr *MaraRevolt) preprocessLinks(ctx context.Context, data [][3]string) { - tx, err := mr.db.Begin() + tx, err := mr.pg.Begin(ctx) if err != nil { ln.Error(ctx, err) return } - defer tx.Rollback() + defer tx.Rollback(ctx) for _, linkkind := range data { kind := linkkind[1] @@ -191,7 +191,7 @@ func (mr *MaraRevolt) preprocessLinks(ctx context.Context, data [][3]string) { msgID := linkkind[2] var count int - if err := tx.QueryRowContext(ctx, "SELECT COUNT(*) FROM s3_uploads WHERE url = ?", link).Scan(&count); err != nil { + if err := tx.QueryRow(ctx, "SELECT COUNT(*) FROM s3_uploads WHERE url = ?", link).Scan(&count); err != nil { ln.Error(ctx, err) continue } @@ -205,12 +205,12 @@ func (mr *MaraRevolt) preprocessLinks(ctx context.Context, data [][3]string) { if werr, ok := err.(*web.Error); ok { if werr.GotStatus == http.StatusNotFound { - tx.ExecContext(ctx, "DELETE FROM discord_users WHERE avatar_url = ?", link) - tx.ExecContext(ctx, "DELETE FROM discord_attachments WHERE url = ?", link) - tx.ExecContext(ctx, "DELETE FROM discord_emoji WHERE url = ?", link) - tx.ExecContext(ctx, "DELETE FROM revolt_attachments WHERE url = ?", link) - tx.ExecContext(ctx, "DELETE FROM revolt_users WHERE avatar_url = ?", link) - tx.ExecContext(ctx, "DELETE FROM revolt_emoji WHERE url = ?", link) + tx.Exec(ctx, "DELETE FROM discord_users WHERE avatar_url = ?", link) + tx.Exec(ctx, "DELETE FROM discord_attachments WHERE url = ?", link) + tx.Exec(ctx, "DELETE FROM discord_emoji WHERE url = ?", link) + tx.Exec(ctx, "DELETE FROM revolt_attachments WHERE url = ?", link) + tx.Exec(ctx, "DELETE FROM revolt_users WHERE avatar_url = ?", link) + tx.Exec(ctx, "DELETE FROM revolt_emoji WHERE url = ?", link) } } @@ -221,7 +221,7 @@ func (mr *MaraRevolt) preprocessLinks(ctx context.Context, data [][3]string) { mr.attachmentUpload.Add(att, len(att.Data)) } - if err := tx.Commit(); err != nil { + if err := tx.Commit(ctx); err != nil { ln.Error(ctx, err) } } @@ -328,12 +328,12 @@ func (mr *MaraRevolt) S3Upload(att []*Attachment) { } func (mr *MaraRevolt) s3Upload(ctx context.Context, att []*Attachment) { - tx, err := mr.db.Begin() + tx, err := mr.pg.Begin(ctx) if err != nil { ln.Error(ctx, err) return } - defer tx.Rollback() + defer tx.Rollback(ctx) for _, att := range att { key := filepath.Join(att.Kind, att.ID) @@ -341,7 +341,7 @@ func (mr *MaraRevolt) s3Upload(ctx context.Context, att []*Attachment) { f := ln.F{"kind": att.Kind, "id": att.ID, "url": att.URL, "content_type": att.ContentType} var count int - if err := tx.QueryRowContext(ctx, "SELECT COUNT(*) FROM s3_uploads WHERE id = ?", att.ID).Scan(&count); err != nil { + if err := tx.QueryRow(ctx, "SELECT COUNT(*) FROM s3_uploads WHERE id = ?", att.ID).Scan(&count); err != nil { ln.Error(ctx, err, f) continue } @@ -366,12 +366,12 @@ func (mr *MaraRevolt) s3Upload(ctx context.Context, att []*Attachment) { continue } - if _, err := tx.ExecContext(ctx, "INSERT INTO s3_uploads(id, url, kind, content_type, created_at, message_id) VALUES (?, ?, ?, ?, ?, ?)", att.ID, att.URL, att.Kind, att.ContentType, att.CreatedAt, att.MessageID); err != nil { + if _, err := tx.Exec(ctx, "INSERT INTO s3_uploads(id, url, kind, content_type, created_at, message_id) VALUES (?, ?, ?, ?, ?, ?)", att.ID, att.URL, att.Kind, att.ContentType, att.CreatedAt, att.MessageID); err != nil { ln.Error(ctx, err, ln.Action("saving upload information to DB"), f) } } - if err := tx.Commit(); err != nil { + if err := tx.Commit(ctx); err != nil { ln.Error(ctx, err) } } diff --git a/cmd/sanguisuga/main.go b/cmd/sanguisuga/main.go index e6f64f3..c85b08b 100644 --- a/cmd/sanguisuga/main.go +++ b/cmd/sanguisuga/main.go @@ -129,18 +129,6 @@ func main() { internal.HandleStartup() hostinfo.SetApp("within.website/x/cmd/sanguisuga") - var programLevel slog.Level - if err := (&programLevel).UnmarshalText([]byte(*slogLevel)); err != nil { - fmt.Fprintf(os.Stderr, "invalid log level %s: %v, using info\n", *slogLevel, err) - programLevel = slog.LevelInfo - } - - h := slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{ - AddSource: true, - Level: programLevel, - }) - slog.SetDefault(slog.New(h)) - var c Config if err := tyson.Unmarshal(*tysonConfig, &c); err != nil { slog.Error("can't unmarshal config", "err", err) @@ -194,7 +182,7 @@ func main() { ircCli.AddCallback("001", func(ev *irc.Event) { ircCli.Join(c.IRC.Channel) }) - ircCli.Log = slog.NewLogLogger(h.WithAttrs([]slog.Attr{slog.String("from", "ircevent")}), slog.LevelInfo) + ircCli.Log = slog.NewLogLogger(slog.Default().Handler().WithAttrs([]slog.Attr{slog.String("from", "ircevent")}), slog.LevelInfo) ircCli.Timeout = 5 * time.Second if err := ircCli.Connect(c.IRC.Server); err != nil { |
