Tips on how to Carry out a Deep Copy in Golang
To carry out a Deep Copy
in Go, you should utilize a struct
kind as follows:
Deep Copying utilizing a struct
in Go#
package deal predominant
import (
"fmt"
)
kind Canine struct {
age int
title string
associates []string
}
func predominant() {
john := Canine{1, "Harry", []string{"Steve", "Matt", "Sarah"}}
jack := john
jack.associates = make([]string, len(john.associates))
copy(jack.associates, harry.associates)
jack.associates = append(jay.associates, "Fred")
fmt.Println(john)
fmt.Println(jack)
}