func (t contentType) String() string {
	return contentTypes[t]
}
String returns the string representation of the content type given a content number.
package client
import (
	"bufio"
	"bytes"
	"compress/gzip"
	"crypto/tls"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"mime/multipart"
	"net/http"
	"net/url"
	"os"
	"path/filepath"
	"strings"
	"time"
	"github.com/asaskevich/govalidator"
	"github.com/intelsdi-x/snap/core"
	"github.com/intelsdi-x/snap/mgmt/rest/v1"
	"github.com/intelsdi-x/snap/mgmt/rest/v1/rbody"
)
var (
	CompressUpload = true
	ErrUnknown     = errors.New("Unknown error calling API")
	ErrNilResponse = errors.New("Nil response from JSON unmarshalling")
	ErrDirNotFile  = errors.New("Provided plugin path is a directory not file")
)
const (
	ContentTypeJSON contentType = iota
	ContentTypeBinary
)
type contentType int
var (
	contentTypes = [...]string{
		"application/json",
		"application/octet-stream",
	}
)
type Client struct {
	URL string
	Version string
	http *http.Client
	prefix string
	Username string
	Password string
}
func parseURL(url string) error {
	if !govalidator.IsURL(url) || !strings.HasPrefix(url, "http") {
		return fmt.Errorf("URL %s is not in the format of http(s)://<ip>:<port>", url)
	}
	return nil
}
type metaOp func(c *Client)
func Password(p string) metaOp {
	return func(c *Client) {
		c.Password = strings.TrimSpace(p)
	}
}
func Username(u string) metaOp {
	return func(c *Client) {
		c.Username = u
	}
}
func Timeout(t time.Duration) metaOp {
	return func(c *Client) {
		c.http.Timeout = t
	}
}
var (
	secureTransport = &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: false},
		IdleConnTimeout: time.Second,
	}
	insecureTransport = &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
		IdleConnTimeout: time.Second,
	}
)
func New(url, ver string, insecure bool, opts ...metaOp) (*Client, error) {
	if err := parseURL(url); err != nil {
		return nil, err
	}
	if ver == "" {
		ver = "v1"
	}
	var t *http.Transport
	if insecure {
		t = insecureTransport
	} else {
		t = secureTransport
	}
	c := &Client{
		URL:     url,
		Version: ver,
		http: &http.Client{
			Transport: t,
		},
	}
	for _, opt := range opts {
		opt(c)
	}
	c.prefix = url + "/" + ver
	return c, nil
}