-
Notifications
You must be signed in to change notification settings - Fork 0
/
facts.go
51 lines (37 loc) · 949 Bytes
/
facts.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
51
package goforeman
import (
"fmt"
"github.com/amine7536/goforeman/context"
)
const factsBasePath = "api/hosts"
type FactsService interface {
Get(context.Context, string, *ListOptions) (Facts, *Response, error)
}
type Facts map[string]map[string]interface{}
type rootFacts struct {
Facts Facts `json:"results"`
}
type FactsServiceOp struct {
client *Client
}
var _ FactsService = &FactsServiceOp{}
func (s *FactsServiceOp) Get(ctx context.Context, hostname string, opt *ListOptions) (Facts, *Response, error) {
path := fmt.Sprintf("%s/%s/facts", factsBasePath, hostname)
req, err := s.client.NewRequest(ctx, "GET", path, opt)
if err != nil {
return nil, nil, err
}
type respWithMeta struct {
rootFacts
ResponseMeta
}
root := new(respWithMeta)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, nil, err
}
if m := &root.ResponseMeta; m != nil {
resp.Meta = m
}
return root.Facts, resp, nil
}