func (c *Client) requestBytes(req *http.Request) ([]byte, http.Header, error) {
	resp, err := c.httpClient.Do(req)
	if err != nil {
		return nil, nil, err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, nil, err
	}
	if resp.StatusCode != 200 {
		var errorResult ApiError
		if json.Unmarshal(body, &errorResult); err != nil {
			return nil, nil, err
		}
		return nil, nil, errorResult
	}
	return body, resp.Header, nil
}
requestJson simplifies the requesting of a JSON response via HTTP, returning an ApiError instance on status codes that don't equal `200 OK`.
package b2
import (
	"encoding/json"
	"io/ioutil"
	"net/http"
)
const (
	v1AuthAccountURL string = "https://api.backblaze.com/b2api/v1/b2_authorize_account"
)
type Credentials struct {
	AccountId      string
	ApplicationKey string
}
type Client struct {
	AccountId   string `json:"accountId"`
	ApiUrl      string `json:"apiUrl"`
	AuthToken   string `json:"authorizationToken"`
	DownloadUrl string `json:"downloadUrl"`
	httpClient *http.Client
}
type ApiError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Status  int    `json:"status"`
}
func (e ApiError) Error() string {
	return e.Message
}
func NewClient(credentials Credentials) (*Client, error) {
	if req, err := http.NewRequest("GET", v1AuthAccountURL, nil); err != nil {
		return nil, err
	} else {
		req.SetBasicAuth(credentials.AccountId, credentials.ApplicationKey)
		var c Client
		c.httpClient = &http.Client{}
		err = c.requestJson(req, &c)
		if err != nil {
			return nil, err
		}
		return &c, nil
	}
}
func (c *Client) setHeaders(req *http.Request) {
	req.Header.Set("Authorization", c.AuthToken)
	req.Header.Set("Content-Type", "application/json; charset=utf-8")
}
func (c *Client) buildRequestUrl(reqPath string) string {
	return c.ApiUrl + reqPath
}
func (c *Client) buildFileRequestUrl(reqPath string) string {
	return c.DownloadUrl + reqPath
}
func (c *Client) requestJson(req *http.Request, result interface{}) error {
	resp, err := c.httpClient.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	if resp.StatusCode != 200 {
		var errorResult ApiError
		if json.Unmarshal(body, &errorResult); err != nil {
			return err
		}
		return errorResult
	}
	return json.Unmarshal(body, result)
}