consul/api/exported_services.go
Tauhid Anjum 5d294b26d3
NET-5824 Exported services api (#20015)
* Exported services api implemented

* Tests added, refactored code

* Adding server tests

* changelog added

* Proto gen added

* Adding codegen changes

* changing url, response object

* Fixing lint error by having namespace and partition directly

* Tests changes

* refactoring tests

* Simplified uniqueness logic for exported services, sorted the response in order of service name

* Fix lint errors, refactored code
2024-01-23 10:06:59 +05:30

50 lines
1.1 KiB
Go

// 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
}