Skip to content

Commit 6d358b0

Browse files
committed
refactoring a code
1 parent 5f0c48a commit 6d358b0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pocket.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ func (c *Client) GetRequestToken(ctx context.Context, redirectURL string, state
162162
}
163163

164164
func (c *Client) parseItems(values *fastjson.Value) []Item {
165+
const indexForItemId int = 13
166+
165167
var (
166168
items []Item
167169
itemId string
@@ -170,9 +172,9 @@ func (c *Client) parseItems(values *fastjson.Value) []Item {
170172

171173
newJsonStr := values.GetObject("list").String()
172174
for index != -1 {
173-
index = strings.Index(newJsonStr, "{\"item_id\":\"")
175+
index = strings.Index(newJsonStr, ":{\"item_id\":\"")
174176
if index != -1 {
175-
for i := index + 12; string(newJsonStr[i]) != "\""; i++ {
177+
for i := index + indexForItemId; string(newJsonStr[i]) != "\""; i++ {
176178
itemId += string(newJsonStr[i])
177179
}
178180

@@ -182,7 +184,7 @@ func (c *Client) parseItems(values *fastjson.Value) []Item {
182184
oldJsonStr := newJsonStr
183185
newJsonStr = ``
184186

185-
for i := index + 12; i != len(oldJsonStr); i++ {
187+
for i := index + indexForItemId; i != len(oldJsonStr); i++ {
186188
newJsonStr += string(oldJsonStr[i])
187189
}
188190
}

0 commit comments

Comments
 (0)