Skip to content

Commit

Permalink
Minor change for type conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
waybackarchiver committed Aug 31, 2024
1 parent ff6e381 commit afdd05d
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion entity/playback.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ const EntityPlayback = "playback"

// Playback represents a Playback in the application.
type Playback struct {
ID int
ID uint64
Source string
}
2 changes: 1 addition & 1 deletion pooling/pooling.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions publish/nostr/nostr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions service/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions service/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
}},
},
},
Expand Down
4 changes: 2 additions & 2 deletions storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions storage/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit afdd05d

Please sign in to comment.