From f57081ab0fbda8b7e48384f1830b09f6cb8d3c44 Mon Sep 17 00:00:00 2001 From: jet2tlf Date: Mon, 3 Jun 2024 14:18:53 -0300 Subject: codecrafters submit [skip ci] --- cmd/mybittorrent/main.go | 3 +++ 1 file changed, 3 insertions(+) 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") } -- cgit v1.2.3