full diff: 616e8db4c3...6068d1894d
a replace rule was needed (similar as in github.com/docker/docker) to fix some
dependency issues;
github.com/docker/cli/cli/trust imports
github.com/theupdateframework/notary/trustpinning tested by
github.com/theupdateframework/notary/trustpinning.test imports
github.com/cloudflare/cfssl/helpers imports
github.com/google/certificate-transparency-go imports
go.etcd.io/etcd/v3 imports
go.etcd.io/etcd/tests/v3/integration imports
go.etcd.io/etcd/server/v3/embed imports
go.opentelemetry.io/otel/semconv: module go.opentelemetry.io/otel@latest found (v1.7.0), but does not contain package go.opentelemetry.io/otel/semconv
github.com/docker/cli/cli/trust imports
github.com/theupdateframework/notary/trustpinning tested by
github.com/theupdateframework/notary/trustpinning.test imports
github.com/cloudflare/cfssl/helpers imports
github.com/google/certificate-transparency-go imports
go.etcd.io/etcd/v3 imports
go.etcd.io/etcd/tests/v3/integration imports
go.etcd.io/etcd/server/v3/embed imports
go.opentelemetry.io/otel/exporters/otlp imports
go.opentelemetry.io/otel/sdk/metric/controller/basic imports
go.opentelemetry.io/otel/metric/registry: module go.opentelemetry.io/otel/metric@latest found (v0.30.0), but does not contain package go.opentelemetry.io/otel/metric/registry
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package deepcopy
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/gogo/protobuf/types"
|
|
)
|
|
|
|
// CopierFrom can be implemented if an object knows how to copy another into itself.
|
|
type CopierFrom interface {
|
|
// Copy takes the fields from src and copies them into the target object.
|
|
//
|
|
// Calling this method with a nil receiver or a nil src may panic.
|
|
CopyFrom(src interface{})
|
|
}
|
|
|
|
// Copy copies src into dst. dst and src must have the same type.
|
|
//
|
|
// If the type has a copy function defined, it will be used.
|
|
//
|
|
// Default implementations for builtin types and well known protobuf types may
|
|
// be provided.
|
|
//
|
|
// If the copy cannot be performed, this function will panic. Make sure to test
|
|
// types that use this function.
|
|
func Copy(dst, src interface{}) {
|
|
switch dst := dst.(type) {
|
|
case *types.Any:
|
|
src := src.(*types.Any)
|
|
dst.TypeUrl = src.TypeUrl
|
|
if src.Value != nil {
|
|
dst.Value = make([]byte, len(src.Value))
|
|
copy(dst.Value, src.Value)
|
|
} else {
|
|
dst.Value = nil
|
|
}
|
|
case *types.Duration:
|
|
src := src.(*types.Duration)
|
|
*dst = *src
|
|
case *time.Duration:
|
|
src := src.(*time.Duration)
|
|
*dst = *src
|
|
case *types.Timestamp:
|
|
src := src.(*types.Timestamp)
|
|
*dst = *src
|
|
case *types.BoolValue:
|
|
src := src.(*types.BoolValue)
|
|
*dst = *src
|
|
case *types.Int64Value:
|
|
src := src.(*types.Int64Value)
|
|
*dst = *src
|
|
case CopierFrom:
|
|
dst.CopyFrom(src)
|
|
default:
|
|
panic(fmt.Sprintf("Copy for %T not implemented", dst))
|
|
}
|
|
|
|
}
|