This is a creation in Article, where the information may have evolved or changed.
Recently took Golang, write a brush star code practice practiced hand.
Program Entry:
Func Main () {for i: = 1; i <; i++ {ing: = getlasting () if strings. Contains (ing, "lucky flash") {InsertIng (i)} else {deleteing (ing)}time. Sleep (* time. Minute)}}
Check for the latest Flash status:
Func getlasting () (text string) {client: = &http. Client{}req, _: = http. Newrequest ("GET", "Http://ing.cnblogs.com/ajax/ing/GetIngList?") inglisttype=my&pageindex=1&pagesize=1&tag=&_=1441948524646 ", nil) req. Header.set ("Content-type", "Application/json; Charset=utf-8 ") req. Header.set ("Cookie", cookie) resp, err: = client. Do (req) defer resp. Body.close () body, err: = Ioutil. ReadAll (resp. Body) If err! = Nil {//handle Error}return string (body)}
Insert a new flash:
ing: = ing{}ing. Publicflag = 1rand. Seed (time. Now (). Unix ()) Ing. Content = "mm" + StrConv. Itoa (Rand. INTN (+)) text, _: = json. Marshal (ing) client: = &http. Client{}req, Err: = http. Newrequest ("POST", "Http://ing.cnblogs.com/ajax/ing/Publish", bytes. Newreader (text)) If err! = Nil {}req. Header.set ("Content-type", "Application/json; Charset=utf-8 ") req. Header.set ("Cookie", cookie) resp, err: = client. Do (req) defer resp. Body.close () body, _: = Ioutil. ReadAll (resp. Body) fmt. Println (String (body))
To delete a flash without star:
Func deleteing (ing string) {begin: = strings. Index (ing, "deling (") L: = Len ("deling (") Ingid: = Ing[begin+l:begin+l+6]fmt. Println ("{ingid:" + Ingid + "}") Client: = &http. Client{}req, _: = http. Newrequest ("POST", "Http://ing.cnblogs.com/ajax/ing/del", strings. Newreader ("{ingid:" +ingid+ "}")) req. Header.set ("Content-type", "Application/json; Charset=utf-8 ") req. Header.set ("Cookie", cookie) resp, err: = client. Do (req) defer resp. Body.close () body, err: = Ioutil. ReadAll (resp. Body) If err! = Nil {fmt. PRINTLN (Err)}fmt. Println (String (body))}
Just Jiangzi! After a good mood to improve again.