forked from hashicorp/consul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexported_services.go
49 lines (37 loc) · 1.08 KB
/
exported_services.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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package api
type ResolvedExportedService struct {
// Service is the name of the service which is exported.
Service string
// Partition of the service
Partition string `json:",omitempty"`
// Namespace of the service
Namespace string `json:",omitempty"`
// Consumers is a list of downstream consumers of the service.
Consumers ResolvedConsumers
}
type ResolvedConsumers struct {
Peers []string `json:",omitempty"`
Partitions []string `json:",omitempty"`
}
func (c *Client) ExportedServices(q *QueryOptions) ([]ResolvedExportedService, *QueryMeta, error) {
r := c.newRequest("GET", "/v1/exported-services")
r.setQueryOptions(q)
rtt, resp, err := c.doRequest(r)
if err != nil {
return nil, nil, err
}
defer closeResponseBody(resp)
if err := requireOK(resp); err != nil {
return nil, nil, err
}
qm := &QueryMeta{}
parseQueryMeta(resp, qm)
qm.RequestTime = rtt
var expSvcs []ResolvedExportedService
if err := decodeBody(resp, &expSvcs); err != nil {
return nil, nil, err
}
return expSvcs, qm, nil
}