func (c *Client) GETV1(endpoint string, v interface{}) (int, error) {
retry:
	req, err := http.NewRequest("GET", endpoint, nil)
	if err != nil {
		return -1, err
	}
	req.Header.Add("Accept", "application/vnd.nsq; version=1.0")
	resp, err := c.c.Do(req)
	if err != nil {
		return -1, err
	}
	body, err := ioutil.ReadAll(resp.Body)
	resp.Body.Close()
	if err != nil {
		return resp.StatusCode, err
	}
	if resp.StatusCode != 200 {
		if resp.StatusCode == 403 && !strings.HasPrefix(endpoint, "https") {
			endpoint, err = httpsEndpoint(endpoint, body)
			if err != nil {
				return resp.StatusCode, err
			}
			goto retry
		}
		return resp.StatusCode, fmt.Errorf("got response %s %q", resp.Status, body)
	}
	err = json.Unmarshal(body, &v)
	if err != nil {
		return resp.StatusCode, err
	}
	return resp.StatusCode, nil
}
GETV1 is a helper function to perform a V1 HTTP request
and parse our NSQ daemon's expected response format, with deadlines.
package http_api
import (
	"crypto/tls"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net"
	"net/http"
	"net/url"
	"strconv"
	"strings"
	"time"
)
type deadlinedConn struct {
	Timeout time.Duration
	net.Conn
}
func (c *deadlinedConn) Read(b []byte) (n int, err error) {
	c.Conn.SetReadDeadline(time.Now().Add(c.Timeout))
	return c.Conn.Read(b)
}
func (c *deadlinedConn) Write(b []byte) (n int, err error) {
	c.Conn.SetWriteDeadline(time.Now().Add(c.Timeout))
	return c.Conn.Write(b)
}
func NewDeadlineTransport(timeout time.Duration) *http.Transport {
	transport := &http.Transport{
		Dial: func(netw, addr string) (net.Conn, error) {
			c, err := net.DialTimeout(netw, addr, timeout)
			if err != nil {
				return nil, err
			}
			return &deadlinedConn{timeout, c}, nil
		},
	}
	return transport
}
type Client struct {
	c *http.Client
}
func NewClient(tlsConfig *tls.Config) *Client {
	transport := NewDeadlineTransport(5 * time.Second)
	transport.TLSClientConfig = tlsConfig
	return &Client{
		c: &http.Client{
			Transport: transport,
		},
	}
}
func (c *Client) NegotiateV1(endpoint string, v interface{}) error {
retry:
	req, err := http.NewRequest("GET", endpoint, nil)
	if err != nil {
		return err
	}
	req.Header.Add("Accept", "application/vnd.nsq; version=1.0")
	resp, err := c.c.Do(req)
	if err != nil {
		return err
	}
	body, err := ioutil.ReadAll(resp.Body)
	resp.Body.Close()
	if err != nil {
		return err
	}
	if resp.StatusCode != 200 {
		if resp.StatusCode == 403 && !strings.HasPrefix(endpoint, "https") {
			endpoint, err = httpsEndpoint(endpoint, body)
			if err != nil {
				return err
			}
			goto retry
		}
		return fmt.Errorf("got response %s %q", resp.Status, body)
	}
	if len(body) == 0 {
		body = []byte("{}")
	}
	if resp.Header.Get("X-NSQ-Content-Type") != "nsq; version=1.0" {
		var u struct {
			StatusCode int64           `json:"status_code"`
			Data       json.RawMessage `json:"data"`
		}
		err := json.Unmarshal(body, u)
		if err != nil {
			return err
		}
		if u.StatusCode != 200 {
			return fmt.Errorf("got 200 response, but api status code of %d", u.StatusCode)
		}
		body = u.Data
	}
	return json.Unmarshal(body, v)
}