func (s *Client) includeStat(rate float32) bool {
	if s == nil {
		return false
	}
	if s.sampler != nil {
		return s.sampler(rate)
	}
	return DefaultSampler(rate)
}
check for nil client, and perform sampling calculation
package statsd
import (
	"fmt"
	"math/rand"
	"strconv"
	"strings"
	"time"
)
var bufPool = newBufferPool()
type StatSender interface {
	Inc(string, int64, float32, ...Tag) error
	Dec(string, int64, float32, ...Tag) error
	Gauge(string, int64, float32, ...Tag) error
	GaugeDelta(string, int64, float32, ...Tag) error
	Timing(string, int64, float32, ...Tag) error
	TimingDuration(string, time.Duration, float32, ...Tag) error
	Set(string, string, float32, ...Tag) error
	SetInt(string, int64, float32, ...Tag) error
	Raw(string, string, float32, ...Tag) error
}
type Statter interface {
	StatSender
	NewSubStatter(string) SubStatter
	SetPrefix(string)
	Close() error
}
type SubStatter interface {
	StatSender
	SetSamplerFunc(SamplerFunc)
	NewSubStatter(string) SubStatter
}
type SamplerFunc func(float32) bool
func DefaultSampler(rate float32) bool {
	if rate < 1 {
		return rand.Float32() < rate
	}
	return true
}
type Client struct {
	prefix string
	sender Sender
	sampler SamplerFunc
	tagFormat TagFormat
}
func (s *Client) Close() error {
	if s == nil {
		return nil
	}
	err := s.sender.Close()
	return err
}
func (s *Client) Inc(stat string, value int64, rate float32, tags ...Tag) error {
	if !s.includeStat(rate) {
		return nil
	}
	return s.submit(stat, "", value, "|c", rate, tags)
}
func (s *Client) Dec(stat string, value int64, rate float32, tags ...Tag) error {
	if !s.includeStat(rate) {
		return nil
	}
	return s.submit(stat, "", -value, "|c", rate, tags)
}
func (s *Client) Gauge(stat string, value int64, rate float32, tags ...Tag) error {
	if !s.includeStat(rate) {
		return nil
	}
	return s.submit(stat, "", value, "|g", rate, tags)
}
func (s *Client) GaugeDelta(stat string, value int64, rate float32, tags ...Tag) error {
	if !s.includeStat(rate) {
		return nil
	}
	if value >= 0 {
		return s.submit(stat, "+", value, "|g", rate, tags)
	}
	return s.submit(stat, "", value, "|g", rate, tags)
}
func (s *Client) Timing(stat string, delta int64, rate float32, tags ...Tag) error {
	if !s.includeStat(rate) {
		return nil
	}
	return s.submit(stat, "", delta, "|ms", rate, tags)
}
func (s *Client) TimingDuration(stat string, delta time.Duration, rate float32, tags ...Tag) error {
	if !s.includeStat(rate) {
		return nil
	}
	ms := float64(delta) / float64(time.Millisecond)
	return s.submit(stat, "", ms, "|ms", rate, tags)
}
func (s *Client) Set(stat string, value string, rate float32, tags ...Tag) error {
	if !s.includeStat(rate) {
		return nil
	}
	return s.submit(stat, "", value, "|s", rate, tags)
}
func (s *Client) SetInt(stat string, value int64, rate float32, tags ...Tag) error {
	if !s.includeStat(rate) {
		return nil
	}
	return s.submit(stat, "", value, "|s", rate, tags)
}
func (s *Client) Raw(stat string, value string, rate float32, tags ...Tag) error {
	if !s.includeStat(rate) {
		return nil
	}
	return s.submit(stat, "", value, "", rate, tags)
}
func (s *Client) SetSamplerFunc(sampler SamplerFunc) {
	s.sampler = sampler
}
func (s *Client) submit(stat, vprefix string, value interface{}, suffix string, rate float32, tags []Tag) error {
	skiptags := false
	if len(tags) == 0 {
		skiptags = true
	}
	buf := bufPool.Get()
	defer bufPool.Put(buf)
	data := buf.Bytes()
	if s.prefix != "" {
		data = append(data, s.prefix...)
		data = append(data, '.')
	}
	data = append(data, stat...)
	if !skiptags && s.tagFormat&AllInfix != 0 {
		data = s.tagFormat.WriteInfix(data, tags)
		skiptags = true
	}
	data = append(data, ':')
	if vprefix != "" {
		data = append(data, vprefix...)
	}
	switch v := value.(type) {
	case string:
		data = append(data, v...)
	case int64:
		data = strconv.AppendInt(data, v, 10)
	case float64:
		data = strconv.AppendFloat(data, v, 'f', -1, 64)
	default:
		return fmt.Errorf("No matching type format")
	}
	if suffix != "" {
		data = append(data, suffix...)
	}
	if rate < 1 {
		data = append(data, "|@"...)
		data = strconv.AppendFloat(data, float64(rate), 'f', 6, 32)
	}
	if !skiptags && s.tagFormat&AllSuffix != 0 {
		data = s.tagFormat.WriteSuffix(data, tags)
	}
	_, err := s.sender.Send(data)
	return err
}