-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.go
58 lines (50 loc) · 1.08 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package kool
import (
"github.com/mitchellh/mapstructure"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
type DeepCopyGen[T any] interface {
DeepCopyInto(*T)
}
func DeepCopy[T any](in, out *T) {
var _in any = in
if d, ok := _in.(DeepCopyGen[T]); ok {
// use deepcopy-gen
d.DeepCopyInto(out)
return
}
mapstructure.Decode(in, out)
}
type List[T any] struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []T `json:"items"`
}
func (listA *List[T]) DeepCopyInto(listB *List[T]) {
*listB = *listA
listB.TypeMeta = listA.TypeMeta
listA.ListMeta.DeepCopyInto(&listB.ListMeta)
if listA.Items != nil {
in, out := &listA.Items, &listB.Items
*out = make([]T, len(*in))
for i := range *in {
DeepCopy[T](&(*in)[i], &(*out)[i])
}
}
return
}
func (in *List[T]) DeepCopy() *List[T] {
if in == nil {
return nil
}
out := new(List[T])
in.DeepCopyInto(out)
return out
}
func (in *List[T]) DeepCopyObject() runtime.Object {
if copy := in.DeepCopy(); copy != nil {
return copy
}
return nil
}