From afdd05d88d8e116145bfa47fc766cfb346af98ca Mon Sep 17 00:00:00 2001 From: Wayback Archiver <66856220+waybackarchiver@users.noreply.github.com> Date: Wed, 28 Aug 2024 14:59:46 +0000 Subject: [PATCH] Minor change for type conversions --- entity/playback.go | 2 +- pooling/pooling.go | 2 +- publish/nostr/nostr.go | 6 +++--- service/discord/discord.go | 4 ++-- service/telegram/telegram.go | 4 ++-- storage/storage.go | 4 ++-- storage/telegram.go | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/entity/playback.go b/entity/playback.go index cc7a2ba2..ec3cb443 100644 --- a/entity/playback.go +++ b/entity/playback.go @@ -9,6 +9,6 @@ const EntityPlayback = "playback" // Playback represents a Playback in the application. type Playback struct { - ID int + ID uint64 Source string } diff --git a/pooling/pooling.go b/pooling/pooling.go index 58254112..9477b41e 100644 --- a/pooling/pooling.go +++ b/pooling/pooling.go @@ -251,7 +251,7 @@ func (p *Pool) Status() Status { return StatusIdle } - if total < int32(cap(p.resource)) { + if int(total) < cap(p.resource) { return StatusIdle } diff --git a/publish/nostr/nostr.go b/publish/nostr/nostr.go index 5b8b5853..1cf2c8eb 100644 --- a/publish/nostr/nostr.go +++ b/publish/nostr/nostr.go @@ -102,7 +102,7 @@ func (n *Nostr) publish(ctx context.Context, note string) error { } g, ctx := errgroup.WithContext(ctx) - var failed int32 + var failed int64 for _, url := range n.opts.NostrRelayURL() { logger.Debug(`publish note to relay: %s`, url) url := url @@ -121,7 +121,7 @@ func (n *Nostr) publish(ctx context.Context, note string) error { status, err := relay.Publish(ctx, ev) if err != nil { - atomic.AddInt32(&failed, 1) + atomic.AddInt64(&failed, 1) return fmt.Errorf("published to %s failed: %v", url, err) } if status != nostr.PublishStatusSucceeded { @@ -131,7 +131,7 @@ func (n *Nostr) publish(ctx context.Context, note string) error { }) } if err := g.Wait(); err != nil { - annihilated := atomic.LoadInt32(&failed) == int32(len(n.opts.NostrRelayURL())) + annihilated := atomic.LoadInt64(&failed) == int64(len(n.opts.NostrRelayURL())) if annihilated { return err } diff --git a/service/discord/discord.go b/service/discord/discord.go index 0f631799..4ffce94c 100644 --- a/service/discord/discord.go +++ b/service/discord/discord.go @@ -205,7 +205,7 @@ func (d *Discord) buttonHandlers() map[string]func(*discord.Session, *discord.In } // Query playback callback data from database - pb, err := d.store.Playback(id) + pb, err := d.store.Playback(uint64(id)) if err != nil { logger.Error("query playback data failed: %v", err) metrics.IncrementWayback(metrics.ServiceDiscord, metrics.StatusFailure) @@ -373,7 +373,7 @@ func (d *Discord) playback(s *discord.Session, i *discord.InteractionCreate) err Label: "wayback", Style: discord.SuccessButton, Disabled: false, - CustomID: strconv.Itoa(pb.ID), + CustomID: strconv.FormatUint(pb.ID, 10), }, }, }, diff --git a/service/telegram/telegram.go b/service/telegram/telegram.go index e716e93c..8685c2ec 100644 --- a/service/telegram/telegram.go +++ b/service/telegram/telegram.go @@ -119,7 +119,7 @@ func (t *Telegram) Serve() (err error) { } // Query playback callback data from database - pb, err := t.store.Playback(id) + pb, err := t.store.Playback(uint64(id)) if err != nil { logger.Error("query playback data failed: %v", err) metrics.IncrementWayback(metrics.ServiceTelegram, metrics.StatusFailure) @@ -345,7 +345,7 @@ func (t *Telegram) playback(message *telegram.Message) error { InlineKeyboard: [][]telegram.InlineButton{ {{ Text: "wayback", - Data: strconv.Itoa(pb.ID), + Data: strconv.FormatUint(pb.ID, 10), }}, }, }, diff --git a/storage/storage.go b/storage/storage.go index cf028d10..a51b7773 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -43,8 +43,8 @@ func (s *Storage) Close() error { return ErrDatabaseNotFound } -func itob(v int) []byte { +func itob(v uint64) []byte { b := make([]byte, 8) - binary.BigEndian.PutUint64(b, uint64(v)) + binary.BigEndian.PutUint64(b, v) return b } diff --git a/storage/telegram.go b/storage/telegram.go index 4ae2d3cf..ee3552d1 100644 --- a/storage/telegram.go +++ b/storage/telegram.go @@ -33,7 +33,7 @@ func (s *Storage) createPlaybackBucket() error { } // Playback returns playback data of the given id. -func (s *Storage) Playback(id int) (*entity.Playback, error) { +func (s *Storage) Playback(id uint64) (*entity.Playback, error) { var pb entity.Playback err := s.db.View(func(tx *bolt.Tx) error { @@ -63,7 +63,7 @@ func (s *Storage) CreatePlayback(pb *entity.Playback) error { } logger.Debug("putting data to bucket, id: %d, value: %s", id, pb.Source) - pb.ID = int(id) + pb.ID = id buf := bytes.NewBufferString(pb.Source).Bytes() return b.Put(itob(pb.ID), buf)