-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathstatistics.go
50 lines (39 loc) · 1.43 KB
/
statistics.go
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package powerdns
import (
"context"
"fmt"
"net/url"
)
// StatisticsService handles communication with the statistics related methods of the Client API
type StatisticsService service
// Statistic structure with JSON API metadata
type Statistic struct {
Name *string `json:"name,omitempty"`
Type *string `json:"type,omitempty"`
// Contrary to the authoritative API specification, the "size" field has actually been implemented as string instead of integer.
Size *string `json:"size,omitempty"`
// The "value" field contains either a string or a list of objects, depending on the "type".
Value interface{} `json:"value,omitempty"`
}
// List retrieves a list of Statistics
func (s *StatisticsService) List(ctx context.Context) ([]Statistic, error) {
req, err := s.client.newRequest(ctx, "GET", fmt.Sprintf("servers/%s/statistics", s.client.VHost), nil, nil)
if err != nil {
return nil, err
}
statistics := make([]Statistic, 0)
_, err = s.client.do(req, &statistics)
return statistics, err
}
// Get retrieves certain Statistics
func (s *StatisticsService) Get(ctx context.Context, statisticName string) ([]Statistic, error) {
query := url.Values{}
query.Add("statistic", statisticName)
req, err := s.client.newRequest(ctx, "GET", fmt.Sprintf("servers/%s/statistics", s.client.VHost), &query, nil)
if err != nil {
return nil, err
}
statistics := make([]Statistic, 0)
_, err = s.client.do(req, &statistics)
return statistics, err
}