mirror of https://github.com/status-im/consul.git
proto: deep-copy PeeringTrustBundle using proto.Clone (#15004)
Fixes a `go vet` warning caused by the pragma.DoNotCopy on the protobuf message type. Originally I'd hoped we wouldn't need any reflection in the proxycfg hot path, but it seems proto.Clone is the only supported way to copy a message.
This commit is contained in:
parent
3d2dffff16
commit
641347fe14
|
@ -329,7 +329,6 @@ codegen-tools:
|
||||||
.PHONY: deep-copy
|
.PHONY: deep-copy
|
||||||
deep-copy:
|
deep-copy:
|
||||||
@$(SHELL) $(CURDIR)/agent/structs/deep-copy.sh
|
@$(SHELL) $(CURDIR)/agent/structs/deep-copy.sh
|
||||||
@$(SHELL) $(CURDIR)/proto/pbpeering/deep-copy.sh
|
|
||||||
@$(SHELL) $(CURDIR)/agent/proxycfg/deep-copy.sh
|
@$(SHELL) $(CURDIR)/agent/proxycfg/deep-copy.sh
|
||||||
|
|
||||||
version:
|
version:
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
readonly PACKAGE_DIR="$(dirname "${BASH_SOURCE[0]}")"
|
|
||||||
cd $PACKAGE_DIR
|
|
||||||
|
|
||||||
# Uses: https://github.com/globusdigital/deep-copy
|
|
||||||
deep-copy -pointer-receiver \
|
|
||||||
-type PeeringTrustBundle \
|
|
||||||
-o ./peering.deepcopy.go \
|
|
||||||
./
|
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
// generated by deep-copy -pointer-receiver -type PeeringTrustBundle -o ./peering.deepcopy.go ./; DO NOT EDIT.
|
|
||||||
|
|
||||||
package pbpeering
|
|
||||||
|
|
||||||
// DeepCopy generates a deep copy of *PeeringTrustBundle
|
|
||||||
func (o *PeeringTrustBundle) DeepCopy() *PeeringTrustBundle {
|
|
||||||
var cp PeeringTrustBundle = *o
|
|
||||||
if o.unknownFields != nil {
|
|
||||||
cp.unknownFields = make([]byte, len(o.unknownFields))
|
|
||||||
copy(cp.unknownFields, o.unknownFields)
|
|
||||||
}
|
|
||||||
if o.RootPEMs != nil {
|
|
||||||
cp.RootPEMs = make([]string, len(o.RootPEMs))
|
|
||||||
copy(cp.RootPEMs, o.RootPEMs)
|
|
||||||
}
|
|
||||||
return &cp
|
|
||||||
}
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/golang/protobuf/ptypes/timestamp"
|
"github.com/golang/protobuf/ptypes/timestamp"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/agent/structs"
|
"github.com/hashicorp/consul/agent/structs"
|
||||||
"github.com/hashicorp/consul/api"
|
"github.com/hashicorp/consul/api"
|
||||||
|
@ -302,3 +303,14 @@ func TimePtrToProto(s *time.Time) *timestamp.Timestamp {
|
||||||
}
|
}
|
||||||
return structs.TimeToProto(*s)
|
return structs.TimeToProto(*s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeepCopy returns a copy of the PeeringTrustBundle that can be passed around
|
||||||
|
// without worrying about the receiver unsafely modifying it. It is used by the
|
||||||
|
// generated DeepCopy methods in proxycfg.
|
||||||
|
func (o *PeeringTrustBundle) DeepCopy() *PeeringTrustBundle {
|
||||||
|
cp, ok := proto.Clone(o).(*PeeringTrustBundle)
|
||||||
|
if !ok {
|
||||||
|
panic(fmt.Sprintf("failed to clone *PeeringTrustBundle, got: %T", cp))
|
||||||
|
}
|
||||||
|
return cp
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue