style: prefer stdlib idioms for errors and http methods

This commit is contained in:
Mathis Maquenne
2026-08-05 21:43:59 +02:00
parent a695fb4de3
commit c1775e5c04
12 changed files with 50 additions and 44 deletions
+3 -2
View File
@@ -2,6 +2,7 @@ package store
import (
"encoding/json"
"errors"
"fmt"
"time"
@@ -24,12 +25,12 @@ func (s *Store) DownloadInfo(trackID string) (*DownloadInfo, error) {
if err := s.db.View(func(tx *bbolt.Tx) error {
b := tx.Bucket(trackBucket)
if b == nil {
return fmt.Errorf("bucket not found")
return errors.New("bucket not found")
}
data := b.Get([]byte(trackID))
if data == nil {
return fmt.Errorf("not found")
return errors.New("not found")
}
return json.Unmarshal(data, &info)
}); err != nil {
+4 -4
View File
@@ -6,19 +6,19 @@ import (
"path/filepath"
"time"
bolt "go.etcd.io/bbolt"
"go.etcd.io/bbolt"
bolterrors "go.etcd.io/bbolt/errors"
)
type Store struct {
db *bolt.DB
db *bbolt.DB
}
func Open(dir string) (*Store, error) {
db, err := bolt.Open(filepath.Join(dir, ".tracks.db"), 0600, &bolt.Options{Timeout: 5 * time.Second})
db, err := bbolt.Open(filepath.Join(dir, ".tracks.db"), 0600, &bbolt.Options{Timeout: 5 * time.Second})
if err != nil {
if errors.Is(err, bolterrors.ErrTimeout) {
return nil, fmt.Errorf("database is already in use by another process")
return nil, errors.New("database is already in use by another process")
}
return nil, fmt.Errorf("failed to open database: %w", err)
}