Skip to content

Commit f96d0a9

Browse files
committed
optimize code
1 parent af68ff3 commit f96d0a9

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

main.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ func main() {
2121
"5aa21c7ae54af10017dc93f8", // 一个想法不一定对
2222
}
2323

24-
s1 := rand.NewSource(time.Now().UnixNano())
25-
r1 := rand.New(s1)
26-
topicdIndex := r1.Intn(len(topics))
24+
s := rand.NewSource(time.Now().UnixNano())
25+
r := rand.New(s)
26+
topicdIndex := r.Intn(len(topics))
2727
url := "https://app.jike.ruguoapp.com/1.0/squarePosts/list"
2828
jsonStr := []byte(`{"topicId": "` + topics[topicdIndex] + `", "limit": 20}`)
2929
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
@@ -43,11 +43,8 @@ func main() {
4343
panic(err)
4444
}
4545

46-
s2 := rand.NewSource(time.Now().UnixNano())
47-
r2 := rand.New(s2)
48-
4946
contentData := dat["data"].([]interface{})
50-
contentIndex := r2.Intn(len(contentData))
47+
contentIndex := r.Intn(len(contentData))
5148
content := contentData[contentIndex].(map[string]interface{})
5249
fmt.Println(content["content"].(string))
5350
fmt.Println("--", (content["topic"].(map[string]interface{})["content"].(string)))

0 commit comments

Comments
 (0)