cmd/cloner: support cloning arbitrarily-nested maps

Fixes #17870

Signed-off-by: Andrew Dunham <andrew@tailscale.com>
This commit is contained in:
Andrew Dunham
2025-11-12 23:22:55 -05:00
committed by Andrew Dunham
parent ca9b68aafd
commit 08e74effc0
4 changed files with 354 additions and 32 deletions
+13 -1
View File
@@ -1,7 +1,7 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
//go:generate go run tailscale.com/cmd/cloner -clonefunc=true -type SliceContainer,InterfaceContainer
//go:generate go run tailscale.com/cmd/cloner -clonefunc=true -type SliceContainer,InterfaceContainer,MapWithPointers,DeeplyNestedMap
// Package clonerex is an example package for the cloner tool.
package clonerex
@@ -32,3 +32,15 @@ func (c *CloneableImpl) Clone() Cloneable {
type InterfaceContainer struct {
Interface Cloneable
}
type MapWithPointers struct {
Nested map[string]*int
WithCloneMethod map[string]*SliceContainer
CloneInterface map[string]Cloneable
}
// DeeplyNestedMap tests arbitrary depth of map nesting (3+ levels)
type DeeplyNestedMap struct {
ThreeLevels map[string]map[string]map[string]int
FourLevels map[string]map[string]map[string]map[string]*SliceContainer
}