diff --git a/pkg/beaconclient/checkbeaconserverstatus.go b/pkg/beaconclient/checkbeaconserverstatus.go index ca0ea9e..4ce3728 100644 --- a/pkg/beaconclient/checkbeaconserverstatus.go +++ b/pkg/beaconclient/checkbeaconserverstatus.go @@ -16,9 +16,11 @@ package beaconclient import ( + "bufio" + "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "strconv" "strings" @@ -71,14 +73,17 @@ func (bc BeaconClient) QueryHeadSync() (Sync, error) { } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + var body bytes.Buffer + buf := bufio.NewWriter(&body) + _, err = io.Copy(buf, resp.Body) + if err != nil { return syncStatus, err } - if err := json.Unmarshal(body, &syncStatus); err != nil { + if err := json.Unmarshal(body.Bytes(), &syncStatus); err != nil { loghelper.LogEndpoint(bcSync).WithFields(log.Fields{ - "rawMessage": string(body), + "rawMessage": body.String(), "err": err, }).Error("Unable to unmarshal sync status") return syncStatus, err @@ -149,14 +154,16 @@ func (bc BeaconClient) queryLighthouseDbInfo() (LighthouseDatabaseInfo, error) { } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + var body bytes.Buffer + buf := bufio.NewWriter(&body) + _, err = io.Copy(buf, resp.Body) if err != nil { return dbInfo, err } - if err := json.Unmarshal(body, &dbInfo); err != nil { + if err := json.Unmarshal(body.Bytes(), &dbInfo); err != nil { loghelper.LogEndpoint(lhDbInfo).WithFields(log.Fields{ - "rawMessage": string(body), + "rawMessage": body.String(), "err": err, }).Error("Unable to unmarshal the lighthouse database information") return dbInfo, err diff --git a/pkg/beaconclient/queryserver.go b/pkg/beaconclient/queryserver.go index 4971e62..d3a89cc 100644 --- a/pkg/beaconclient/queryserver.go +++ b/pkg/beaconclient/queryserver.go @@ -18,8 +18,10 @@ package beaconclient import ( + "bufio" + "bytes" "fmt" - "io/ioutil" + "io" "net/http" log "github.com/sirupsen/logrus" @@ -59,11 +61,13 @@ func querySsz(endpoint string, slot Slot) ([]byte, int, error) { return nil, rc, fmt.Errorf("HTTP Error: %d", rc) } - body, err := ioutil.ReadAll(response.Body) + var body bytes.Buffer + buf := bufio.NewWriter(&body) + _, err = io.Copy(buf, response.Body) if err != nil { loghelper.LogSlotError(slot.Number(), err).Error("Unable to turn response into a []bytes array!") return nil, rc, fmt.Errorf("Unable to turn response into a []bytes array!: %s", err.Error()) } - return body, rc, nil + return body.Bytes(), rc, nil }