Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

Commit

Permalink
deepcopy
Browse files Browse the repository at this point in the history
  • Loading branch information
Lack30 committed Jun 17, 2021
1 parent 62dc769 commit 3b3e1fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmd/protoc-gen-deepcopy/plugin/deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ func (g *deepcopy) generateMessage(file *generator.FileDescriptor, msg *generato
g.P(fmt.Sprintf(`return &%s.GroupVersionKind{Group: "%s", Version: "%s", Kind: "%s"}`, pkg.Use(), group, version, mname))
g.P("}")
g.P()
g.P(fmt.Sprintf(`// DeepCopyFrom is an auto-generated deepcopy function, copying value from %s.`, mname))
g.P(fmt.Sprintf(`func (in *%s) DeepCopyFrom(src %s.Object) {`, mname, pkg.Use()))
g.P(fmt.Sprintf(`o := src.(*%s)`, mname))
g.P(`o.DeepCopyInto(in)`)
g.P(`}`)
g.P(fmt.Sprintf(`// DeepCopy is an auto-generated deepcopy function, copying the receiver, creating a new %s.`, mname))
g.P(fmt.Sprintf(`func (in *%s) DeepCopy() %s.Object {`, mname, pkg.Use()))
}
Expand Down
4 changes: 3 additions & 1 deletion util/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func FromGVK(s string) *GroupVersionKind {
type Object interface {
// GVK get the GroupVersionKind of Object
GVK() *GroupVersionKind
// DeepCopyFrom deep copy the struct from another
DeepCopyFrom(Object)
// DeepCopy deep copy the struct
DeepCopy() Object
}
Expand All @@ -85,7 +87,7 @@ var oset = NewObjectSet()
type ObjectSet struct {
sync.RWMutex

sets map[string]Object
sets map[string]Object

OnCreate func(in Object) Object
}
Expand Down

0 comments on commit 3b3e1fa

Please sign in to comment.