You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/proto/private/pbpeerstream/convert.go

41 lines
1018 B

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package pbpeerstream
import (
"fmt"
"github.com/hashicorp/consul/agent/structs"
pbservice "github.com/hashicorp/consul/proto/private/pbservice"
)
// CheckServiceNodesToStruct converts the contained CheckServiceNodes to their structs equivalent.
func (s *ExportedService) CheckServiceNodesToStruct() ([]structs.CheckServiceNode, error) {
if s == nil {
return nil, nil
}
resp := make([]structs.CheckServiceNode, 0, len(s.Nodes))
for _, pb := range s.Nodes {
instance, err := pbservice.CheckServiceNodeToStructs(pb)
if err != nil {
return resp, fmt.Errorf("failed to convert instance: %w", err)
}
resp = append(resp, *instance)
}
return resp, nil
}
func ExportedServiceListFromStruct(e *structs.ExportedServiceList) *ExportedServiceList {
services := make([]string, 0, len(e.Services))
for _, s := range e.Services {
services = append(services, s.String())
}
return &ExportedServiceList{
Services: services,
}
}