aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorjet2tlf <jet2tlf@gmail.com>2024-06-03 17:18:53 +0000
committerjet2tlf <jet2tlf@gmail.com>2024-06-03 17:18:53 +0000
commitf57081ab0fbda8b7e48384f1830b09f6cb8d3c44 (patch)
treee2917d5ecc8e5c45b06fa6f1547ec41812834baa /cmd
parent3a6e39f8a82299f21b1efa8aaa9a1ea748d25628 (diff)
downloadbittorrent-go-f57081ab0fbda8b7e48384f1830b09f6cb8d3c44.tar.gz
bittorrent-go-f57081ab0fbda8b7e48384f1830b09f6cb8d3c44.zip
codecrafters submit [skip ci]
Diffstat (limited to 'cmd')
-rw-r--r--cmd/mybittorrent/main.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/cmd/mybittorrent/main.go b/cmd/mybittorrent/main.go
index 5c2a12f..87095ae 100644
--- a/cmd/mybittorrent/main.go
+++ b/cmd/mybittorrent/main.go
@@ -5,6 +5,7 @@ import (
"fmt"
"os"
"strconv"
+ "strings"
"unicode"
// bencode "github.com/jackpal/bencode-go" // Available if you need it!
)
@@ -28,6 +29,8 @@ func decodeBencode(bencodedString string) (interface{}, error) {
}
return bencodedString[firstColonIndex+1 : firstColonIndex+1+length], nil
+ } else if rune(bencodedString[0]) == 'i' {
+ return strconv.Atoi(bencodedString[1:strings.IndexByte(bencodedString, 'e')])
} else {
return "", fmt.Errorf("only strings are supported at the moment")
}