mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-01 07:21:17 +00:00
refactor(model): use log.Fatal for Encode128 contract guard per project convention
This commit is contained in:
parent
da4da4e749
commit
4f279e4866
@ -6,6 +6,8 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
|
||||
"github.com/navidrome/navidrome/log"
|
||||
)
|
||||
|
||||
func NewRandom() string {
|
||||
@ -17,7 +19,7 @@ func NewRandom() string {
|
||||
// Encode128 renders a 16-byte value as the canonical 22-char zero-padded base62 id.
|
||||
func Encode128(b []byte) string {
|
||||
if len(b) != 16 {
|
||||
panic(fmt.Sprintf("id.Encode128: expected 16 bytes, got %d", len(b)))
|
||||
log.Fatal("Encode128: expected 16 bytes", "got", len(b))
|
||||
}
|
||||
return fmt.Sprintf("%022s", new(big.Int).SetBytes(b).Text(62))
|
||||
}
|
||||
|
||||
@ -22,10 +22,6 @@ var _ = Describe("Encode128/Decode128", func() {
|
||||
Expect(id.Decode128(s)).To(Equal(b))
|
||||
})
|
||||
|
||||
It("panics on non-16-byte input", func() {
|
||||
Expect(func() { id.Encode128(make([]byte, 15)) }).To(Panic())
|
||||
})
|
||||
|
||||
It("rejects invalid input", func() {
|
||||
_, err := id.Decode128("short")
|
||||
Expect(err).To(HaveOccurred())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user