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...)
}
|