mirror of https://github.com/status-im/consul.git
mesh: adding type aliases for mesh resource usage (#18448)
Introduces some simple type aliases for DecodedResource[*X] wrappers for each type which cut down on the verbosity
This commit is contained in:
parent
0d60380214
commit
17667a1c75
|
@ -0,0 +1,20 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/consul/internal/resource"
|
||||
pbcatalog "github.com/hashicorp/consul/proto-public/pbcatalog/v1alpha1"
|
||||
pbmesh "github.com/hashicorp/consul/proto-public/pbmesh/v1alpha1"
|
||||
)
|
||||
|
||||
type (
|
||||
DecodedHTTPRoute = resource.DecodedResource[*pbmesh.HTTPRoute]
|
||||
DecodedGRPCRoute = resource.DecodedResource[*pbmesh.GRPCRoute]
|
||||
DecodedTCPRoute = resource.DecodedResource[*pbmesh.TCPRoute]
|
||||
DecodedDestinationPolicy = resource.DecodedResource[*pbmesh.DestinationPolicy]
|
||||
DecodedComputedRoutes = resource.DecodedResource[*pbmesh.ComputedRoutes]
|
||||
DecodedFailoverPolicy = resource.DecodedResource[*pbcatalog.FailoverPolicy]
|
||||
DecodedService = resource.DecodedResource[*pbcatalog.Service]
|
||||
)
|
|
@ -20,6 +20,23 @@ type DecodedResource[T proto.Message] struct {
|
|||
Data T
|
||||
}
|
||||
|
||||
func (d *DecodedResource[T]) GetResource() *pbresource.Resource {
|
||||
if d == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return d.Resource
|
||||
}
|
||||
|
||||
func (d *DecodedResource[T]) GetData() T {
|
||||
if d == nil {
|
||||
var zero T
|
||||
return zero
|
||||
}
|
||||
|
||||
return d.Data
|
||||
}
|
||||
|
||||
// Decode will generically decode the provided resource into a 2-field
|
||||
// structure that holds onto the original Resource and the decoded contents.
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue