Browse Source

Fix multiple requests

io.Reader after first request became empty
main
Дмитрий 2 years ago
parent
commit
4f5115f94a
  1. 11
      cmd/client_server/client.go

11
cmd/client_server/client.go

@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"log" "log"
"math" "math"
@ -16,14 +15,14 @@ import (
"time" "time"
) )
func sendRequest(url string, body *io.Reader) (req_types.SuccesResponse, error) { func sendRequest(url string, body *[]byte) (req_types.SuccesResponse, error) {
var pResp req_types.SuccesResponse var pResp req_types.SuccesResponse
c := &http.Client{ c := &http.Client{
Timeout: 200 * time.Millisecond, Timeout: 200 * time.Millisecond,
} }
resp, err := c.Post(url, "application/json", *body) resp, err := c.Post(url, "application/json", bytes.NewReader(*body))
if err != nil { if err != nil {
eText := fmt.Sprintf("Error: partner %v not responding", url) eText := fmt.Sprintf("Error: partner %v not responding", url)
@ -45,8 +44,8 @@ func sendRequest(url string, body *io.Reader) (req_types.SuccesResponse, error)
} }
// Create requset body based in incoming reqest `ir` and return // Create requset body based in incoming reqest `ir` and return
// `OutgoingRequest` as bytes.Reader from marshaled JSON // `OutgoingRequest` as []byte from marshaled JSON
func constructPartnersRequestBody(ir *req_types.IncomingRequest) io.Reader { func constructPartnersRequestBody(ir *req_types.IncomingRequest) []byte {
var outReqBody req_types.OutgoingRequest var outReqBody req_types.OutgoingRequest
var imps []req_types.Imp var imps []req_types.Imp
@ -63,7 +62,7 @@ func constructPartnersRequestBody(ir *req_types.IncomingRequest) io.Reader {
outReqBody.Imp = imps outReqBody.Imp = imps
outReqBody.Context = ir.Context outReqBody.Context = ir.Context
t, _ := json.Marshal(outReqBody) t, _ := json.Marshal(outReqBody)
return bytes.NewReader(t) return t
} }
// map[imp.id]map[imp.id.price] // map[imp.id]map[imp.id.price]

Loading…
Cancel
Save