File: auto.go

package info (click to toggle)
prometheus-bind-exporter 0.2~git20161221%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,016 kB
  • sloc: xml: 4,163; sh: 63; makefile: 41
file content (28 lines) | stat: -rw-r--r-- 826 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package auto

import (
	"net/http"

	"github.com/digitalocean/bind_exporter/bind"
	"github.com/digitalocean/bind_exporter/bind/v2"
	"github.com/digitalocean/bind_exporter/bind/v3"
)

// Client is a client which automatically detects the statistics version of the
// BIND server and delegates the request to the correct versioned client.
type Client struct {
	*bind.XMLClient
}

// NewClient returns an initialized Client.
func NewClient(url string, c *http.Client) *Client {
	return &Client{XMLClient: bind.NewXMLClient(url, c)}
}

// Stats implements bind.Stats.
func (c *Client) Stats(g ...bind.StatisticGroup) (bind.Statistics, error) {
	if err := c.Get(v3.StatusPath, &bind.Statistics{}); err == nil {
		return (&v3.Client{XMLClient: c.XMLClient}).Stats(g...)
	}
	return (&v2.Client{XMLClient: c.XMLClient}).Stats(g...)
}