forked from etcinit/gonduit
-
Notifications
You must be signed in to change notification settings - Fork 22
/
phid.go
61 lines (47 loc) · 1.27 KB
/
phid.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
52
53
54
55
56
57
58
59
60
61
package gonduit
import (
"github.com/uber/gonduit/entities"
"github.com/uber/gonduit/requests"
"github.com/uber/gonduit/responses"
)
// PHIDLookup calls the phid.lookup endpoint.
func (c *Conn) PHIDLookup(
req requests.PHIDLookupRequest,
) (responses.PHIDLookupResponse, error) {
var r responses.PHIDLookupResponse
if err := c.Call("phid.lookup", &req, &r); err != nil {
return nil, err
}
return r, nil
}
// PHIDLookupSingle calls the phid.lookup endpoint with a single name.
func (c *Conn) PHIDLookupSingle(name string) (*entities.PHIDResult, error) {
req := requests.PHIDLookupRequest{
Names: []string{name},
}
resp, err := c.PHIDLookup(req)
if err != nil {
return nil, err
}
return resp[name], nil
}
// PHIDQuery calls the phid.query endpoint.
func (c *Conn) PHIDQuery(
req requests.PHIDQueryRequest,
) (responses.PHIDQueryResponse, error) {
var r responses.PHIDQueryResponse
if err := c.Call("phid.query", &req, &r); err != nil {
return nil, err
}
return r, nil
}
// PHIDQuerySingle calls the phid.query endpoint with a single phid.
func (c *Conn) PHIDQuerySingle(phid string) (*entities.PHIDResult, error) {
resp, err := c.PHIDQuery(requests.PHIDQueryRequest{
PHIDs: []string{phid},
})
if err != nil {
return nil, err
}
return resp[phid], nil
}