func (p *Point) PrecisionString(precison string) string {
	return p.pt.PrecisionString(precison)
}
PrecisionString returns a line-protocol string of the Point, at precision
package client
import (
	"bytes"
	"crypto/tls"
	"encoding/json"
	"errors"
	"fmt"
	"io/ioutil"
	"net"
	"net/http"
	"net/url"
	"time"
	"github.com/influxdata/influxdb/models"
)
const (
	UDPPayloadSize = 512
)
type HTTPConfig struct {
	Addr string
	Username string
	Password string
	UserAgent string
	Timeout time.Duration
	InsecureSkipVerify bool
	TLSConfig *tls.Config
}
type UDPConfig struct {
	Addr string
	PayloadSize int
}
type BatchPointsConfig struct {
	Precision string
	Database string
	RetentionPolicy string
	WriteConsistency string
}
type Client interface {
	Ping(timeout time.Duration) (time.Duration, string, error)
	Write(bp BatchPoints) error
	Query(q Query) (*Response, error)
	Close() error
}
func NewHTTPClient(conf HTTPConfig) (Client, error) {
	if conf.UserAgent == "" {
		conf.UserAgent = "InfluxDBClient"
	}
	u, err := url.Parse(conf.Addr)
	if err != nil {
		return nil, err
	} else if u.Scheme != "http" && u.Scheme != "https" {
		m := fmt.Sprintf("Unsupported protocol scheme: %s, your address"+
			" must start with http:// or https://", u.Scheme)
		return nil, errors.New(m)
	}
	tr := &http.Transport{
		TLSClientConfig: &tls.Config{
			InsecureSkipVerify: conf.InsecureSkipVerify,
		},
	}
	if conf.TLSConfig != nil {
		tr.TLSClientConfig = conf.TLSConfig
	}
	return &client{
		url:       u,
		username:  conf.Username,
		password:  conf.Password,
		useragent: conf.UserAgent,
		httpClient: &http.Client{
			Timeout:   conf.Timeout,
			Transport: tr,
		},
	}, nil
}
func (c *client) Ping(timeout time.Duration) (time.Duration, string, error) {
	now := time.Now()
	u := c.url
	u.Path = "ping"
	req, err := http.NewRequest("GET", u.String(), nil)
	if err != nil {
		return 0, "", err
	}
	req.Header.Set("User-Agent", c.useragent)
	if c.username != "" {
		req.SetBasicAuth(c.username, c.password)
	}
	if timeout > 0 {
		params := req.URL.Query()
		params.Set("wait_for_leader", fmt.Sprintf("%.0fs", timeout.Seconds()))
		req.URL.RawQuery = params.Encode()
	}
	resp, err := c.httpClient.Do(req)
	if err != nil {
		return 0, "", err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return 0, "", err
	}
	if resp.StatusCode != http.StatusNoContent {
		var err = fmt.Errorf(string(body))
		return 0, "", err
	}
	version := resp.Header.Get("X-Influxdb-Version")
	return time.Since(now), version, nil
}
func (c *client) Close() error {
	return nil
}
func NewUDPClient(conf UDPConfig) (Client, error) {
	var udpAddr *net.UDPAddr
	udpAddr, err := net.ResolveUDPAddr("udp", conf.Addr)
	if err != nil {
		return nil, err
	}
	conn, err := net.DialUDP("udp", nil, udpAddr)
	if err != nil {
		return nil, err
	}
	payloadSize := conf.PayloadSize
	if payloadSize == 0 {
		payloadSize = UDPPayloadSize
	}
	return &udpclient{
		conn:        conn,
		payloadSize: payloadSize,
	}, nil
}
func (uc *udpclient) Ping(timeout time.Duration) (time.Duration, string, error) {
	return 0, "", nil
}
func (uc *udpclient) Close() error {
	return uc.conn.Close()
}
type client struct {
	url        *url.URL
	username   string
	password   string
	useragent  string
	httpClient *http.Client
}
type udpclient struct {
	conn        *net.UDPConn
	payloadSize int
}
type BatchPoints interface {
	AddPoint(p *Point)
	AddPoints(ps []*Point)
	Points() []*Point
	Precision() string
	SetPrecision(s string) error
	Database() string
	SetDatabase(s string)
	WriteConsistency() string
	SetWriteConsistency(s string)
	RetentionPolicy() string
	SetRetentionPolicy(s string)
}
func NewBatchPoints(conf BatchPointsConfig) (BatchPoints, error) {
	if conf.Precision == "" {
		conf.Precision = "ns"
	}
	if _, err := time.ParseDuration("1" + conf.Precision); err != nil {
		return nil, err
	}
	bp := &batchpoints{
		database:         conf.Database,
		precision:        conf.Precision,
		retentionPolicy:  conf.RetentionPolicy,
		writeConsistency: conf.WriteConsistency,
	}
	return bp, nil
}
type batchpoints struct {
	points           []*Point
	database         string
	precision        string
	retentionPolicy  string
	writeConsistency string
}
func (bp *batchpoints) AddPoint(p *Point) {
	bp.points = append(bp.points, p)
}
func (bp *batchpoints) AddPoints(ps []*Point) {
	bp.points = append(bp.points, ps...)
}
func (bp *batchpoints) Points() []*Point {
	return bp.points
}
func (bp *batchpoints) Precision() string {
	return bp.precision
}
func (bp *batchpoints) Database() string {
	return bp.database
}
func (bp *batchpoints) WriteConsistency() string {
	return bp.writeConsistency
}
func (bp *batchpoints) RetentionPolicy() string {
	return bp.retentionPolicy
}
func (bp *batchpoints) SetPrecision(p string) error {
	if _, err := time.ParseDuration("1" + p); err != nil {
		return err
	}
	bp.precision = p
	return nil
}
func (bp *batchpoints) SetDatabase(db string) {
	bp.database = db
}
func (bp *batchpoints) SetWriteConsistency(wc string) {
	bp.writeConsistency = wc
}
func (bp *batchpoints) SetRetentionPolicy(rp string) {
	bp.retentionPolicy = rp
}
type Point struct {
	pt models.Point
}
func NewPoint(
	name string,
	tags map[string]string,
	fields map[string]interface{},
	t ...time.Time,
) (*Point, error) {
	var T time.Time
	if len(t) > 0 {
		T = t[0]
	}
	pt, err := models.NewPoint(name, tags, fields, T)
	if err != nil {
		return nil, err
	}
	return &Point{
		pt: pt,
	}, nil
}
func (p *Point) String() string {
	return p.pt.String()
}