mirror of
https://github.com/status-im/consul.git
synced 2025-01-09 13:26:07 +00:00
5d294b26d3
* 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
50 lines
1.1 KiB
Go
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
|
|
}
|