func (c *Client) Count(key string, delta, samplingRate float64) error {
	msg := []byte(key)
	msg = append(msg, ':')
	msg = strconv.AppendFloat(msg, delta, 'f', -1, 64)
	msg = append(msg, []byte("|c")...)
	switch {
	case samplingRate > 1 || samplingRate <= 0:
		return ErrSamplingRate
	case samplingRate == 1:
	default:
		msg = append(msg, '@')
		msg = strconv.AppendFloat(msg, samplingRate, 'f', -1, 64)
	}
	if c.buffered {
		c.incoming <- msg
		return nil
	}
	return c.send(msg)
}
Count submits a statsd count message with the given key, value, and sampling rate.
package gostc
import (
	"errors"
	"io"
	"math/rand"
	"net"
	"strconv"
	"time"
)
type Client struct {
	c        io.WriteCloser
	buffered bool
	incoming chan []byte
	quit     chan chan bool
}
func NewClient(addr string) (*Client, error) {
	u, err := net.ResolveUDPAddr("udp", addr)
	if err != nil {
		return nil, err
	}
	c, err := net.DialUDP("udp", nil, u)
	if err != nil {
		return nil, err
	}
	client := &Client{
		c: c,
	}
	return client, nil
}
func NewBufferedClient(addr string, queueSize int, maxPacketBytes int, minFlush time.Duration) (*Client, error) {
	c, err := NewClient(addr)
	if err != nil {
		return nil, err
	}
	c.buffered = true
	c.incoming = make(chan []byte, queueSize)
	c.quit = make(chan chan bool)
	go c.bufferAndSend(maxPacketBytes, minFlush)
	return c, nil
}
const (
	DefaultQueueSize = 100
	DefaultMaxPacketBytes = 1000
	DefaultMinFlush       = time.Second
)
func NewDefaultBufferedClient(addr string) (*Client, error) {
	return NewBufferedClient(addr, DefaultQueueSize, DefaultMaxPacketBytes, DefaultMinFlush)
}
func (c *Client) send(b []byte) error {
	_, err := c.c.Write(b)
	return err
}
func (c *Client) bufferAndSend(maxPacketBytes int, minFlush time.Duration) {
	timer := time.NewTimer(minFlush)
	buf := make([]byte, 0, maxPacketBytes)
	for {
		select {
		case <-timer.C:
			if len(buf) > 0 {
				c.send(buf)
				buf = buf[:0]
			}
			timer.Reset(minFlush)
		case msg := <-c.incoming:
			if len(buf)+len(msg)+1 > maxPacketBytes {
				c.send(buf)
				buf = buf[:0]
				timer.Reset(minFlush)
			}
			if len(buf) > 0 {
				buf = append(buf, '\n')
			}
			buf = append(buf, msg...)
		case q := <-c.quit:
			for msg := range c.incoming {
				if len(buf)+len(msg)+1 > maxPacketBytes {
					c.send(buf)
					buf = buf[:0]
				}
				if len(buf) > 0 {
					buf = append(buf, '\n')
				}
				buf = append(buf, msg...)
			}
			if len(buf) > 0 {
				c.send(buf)
			}
			q <- true
			return
		}
	}
}
func (c *Client) Close() error {
	if c.buffered {
		q := make(chan bool)
		c.quit <- q
		close(c.incoming)
		<-q
	}
	return c.c.Close()
}
var ErrSamplingRate = errors.New("sampling rate must be in (0, 1]")