MCPcopy
hub / github.com/Terry-Mao/goim / startPush

Function startPush

benchmarks/push/main.go:89–120  ·  view source on GitHub ↗
(b, e int)

Source from the content-addressed store, hash-verified

87}
88
89func startPush(b, e int) {
90 log.Printf("start Push from %d to %d", b, e)
91 bodys := make([][]byte, e-b)
92 for i := 0; i < e-b; i++ {
93 msg := &pushBodyMsg{Msg: json.RawMessage(testContent), UserID: int64(b)}
94 body, err := json.Marshal(msg)
95 if err != nil {
96 panic(err)
97 }
98 bodys[i] = body
99 }
100
101 for {
102 for i := 0; i < len(bodys); i++ {
103 resp, err := httpPost(fmt.Sprintf("http://%s/goim/push/mids?operation=1000&mids=%d", os.Args[3], b), "application/x-www-form-urlencoded", bytes.NewBuffer(bodys[i]))
104 if err != nil {
105 log.Printf("post error (%v)", err)
106 continue
107 }
108
109 body, err := ioutil.ReadAll(resp.Body)
110 if err != nil {
111 log.Printf("post error (%v)", err)
112 return
113 }
114 resp.Body.Close()
115
116 log.Printf("response %s", string(body))
117 //time.Sleep(50 * time.Millisecond)
118 }
119 }
120}
121
122func httpPost(url string, contentType string, body io.Reader) (*http.Response, error) {
123 req, err := http.NewRequest("POST", url, body)

Callers 1

mainFunction · 0.70

Calls 4

PrintfMethod · 0.80
httpPostFunction · 0.70
CloseMethod · 0.65
MarshalMethod · 0.45

Tested by

no test coverage detected