prysmaticlabs / prysm

Use http.NoBody instead of nil in http.NewRequest calls GO-R4001
Anti-pattern
Major
2 months agoa year old
http.NoBody should be preferred to the nil request body
 47// If an HTTP error is returned, the body is decoded as a DefaultJsonError JSON object and returned as the first return value.
 48func (c BeaconApiJsonRestHandler) Get(ctx context.Context, endpoint string, resp interface{}) error {
 49	url := c.host + endpoint
 50	req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) 51	if err != nil {
 52		return errors.Wrapf(err, "failed to create request for endpoint %s", url)
 53	}
http.NoBody should be preferred to the nil request body
 78	allTopics := strings.Join(h.topics, ",")
 79	log.WithField("topics", allTopics).Info("Listening to Beacon API events")
 80	fullUrl := h.host + "/eth/v1/events?topics=" + allTopics
 81	req, err := http.NewRequestWithContext(h.ctx, http.MethodGet, fullUrl, nil) 82	if err != nil {
 83		eventsChannel <- &Event{
 84			EventType: EventConnectionError,