-
Notifications
You must be signed in to change notification settings - Fork 59
/
phid.go
80 lines (65 loc) · 1.8 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package conduit
type pPHIDLookup struct {
Names []string `json:"names"`
Session *Session `json:"__conduit__"`
}
// PHIDLookupResponse is the result of phid.lookup operations.
type PHIDLookupResponse map[string]*PHIDResult
// PHIDResult is a result item of phid operations.
type PHIDResult struct {
PHID string `json:"phid"`
URI string `json:"uri"`
TypeName string `json:"typeName"`
Type string `json:"type"`
Name string `json:"name"`
FullName string `json:"fullName"`
Status string `json:"status"`
}
// PHIDLookup calls the phid.lookup endpoint.
func (c *Conn) PHIDLookup(names []string) (PHIDLookupResponse, error) {
p := &pPHIDLookup{
Names: names,
Session: c.Session,
}
var r PHIDLookupResponse
if err := c.Call("phid.lookup", p, &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) (*PHIDResult, error) {
resp, err := c.PHIDLookup([]string{name})
if err != nil {
return nil, err
}
r := resp[name]
return r, nil
}
type pPHIDQuery struct {
PHIDs []string `json:"phids"`
Session *Session `json:"__conduit__"`
}
// PHIDQueryResponse is the result of phid.query operations.
type PHIDQueryResponse map[string]*PHIDResult
// PHIDQuery calls the phid.query endpoint.
func (c *Conn) PHIDQuery(phids []string) (PHIDQueryResponse, error) {
p := &pPHIDQuery{
PHIDs: phids,
Session: c.Session,
}
var r PHIDQueryResponse
if err := c.Call("phid.query", p, &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) (*PHIDResult, error) {
resp, err := c.PHIDQuery([]string{phid})
if err != nil {
return nil, err
}
r := resp[phid]
return r, nil
}