-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathresolve.go
48 lines (38 loc) · 1.06 KB
/
resolve.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
package qcon
import (
"context"
)
// Resolve returns a list of URL strings for accessing the server
// using the provided QuickConnect ID. The URL strings are in
// ranked order, most preferred first and only those with verified
// connectivity are returned.
//
// Resolve is a wrapper to (Client) Resolve() using DefaultClient
func Resolve(ctx context.Context, id string) ([]string, error) {
c := DefaultClient
return c.Resolve(ctx, id)
}
// Resolve returns a list of URL strings for accessing the server
// using the provided QuickConnect ID. The URL strings are in
// ranked order, most preferred first and only those with verified
// connectivity are returned.
func (c Client) Resolve(ctx context.Context, id string) ([]string, error) {
info, err := c.GetInfo(ctx, id)
if err != nil {
return nil, err
}
err = c.UpdateState(ctx, &info)
if err != nil {
return nil, err
}
var urls []string
for _, r := range info.Records {
if r.State == StateOK {
urls = append(urls, r.URL)
}
}
if len(urls) == 0 {
return nil, ErrCannotAccess
}
return urls, nil
}