diting.go 1.3 KB
Newer Older
Y
Your Name 已提交
1 2 3 4 5 6 7 8
package diting

//ConfigHandleFunc configHandleFunc
type ConfigHandleFunc func() interface{}

//Constructor constructor
type Constructor interface {
	Namespace() string
Y
Your Name 已提交
9
	Create(conf string) (Factory, error)
Y
Your Name 已提交
10 11 12 13 14
	Close()
}

//Factory factory
type Factory interface {
Y
Your Name 已提交
15
	NewCounter(opt *CounterOpts) (Counter, error)
Y
Your Name 已提交
16
	//NewSummary(opt *SummaryOpts) (Summary,error)
Y
Your Name 已提交
17 18
	NewHistogram(opt *HistogramOpts) (Histogram, error)
	NewGauge(opt *GaugeOpts) (Gauge, error)
Y
Your Name 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
}

//Factories factories
type Factories []Factory

//NewCounter new counter
func (fs Factories) NewCounter(opt *CounterOpts) (Counters, error) {
	cs := make(Counters, 0, len(fs))
	for _, f := range fs {

		s, err := f.NewCounter(opt)
		if err != nil {
			continue
		}
		cs = append(cs, s)
	}
	return cs, nil
}

//NewHistogram new histogram
func (fs Factories) NewHistogram(opt *HistogramOpts) (Histograms, error) {
	hs := make(Histograms, 0, len(fs))
	for _, f := range fs {

		h, err := f.NewHistogram(opt)
		if err != nil {
			continue
		}
		hs = append(hs, h)
	}
	return hs, nil
}

//NewGauge new gauge
func (fs Factories) NewGauge(opt *GaugeOpts) (Gauges, error) {
	gs := make(Gauges, 0, len(fs))
	for _, f := range fs {

		g, err := f.NewGauge(opt)
		if err != nil {
			continue
		}
		gs = append(gs, g)
	}
	return gs, nil
}