To perform a Deep Copy in Go, you can use a struct type as follows:

Deep Copying using a struct in 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
package main

import (
    "fmt"
)

type Dog struct {
    age     int
    name    string
    friends []string
}

func main() {
    john := Dog{1, "Harry", []string{"Steve", "Matt", "Sarah"}}
    jack := john

    jack.friends = make([]string, len(john.friends))
    copy(jack.friends, harry.friends)

    jack.friends = append(jay.friends, "Fred")

    fmt.Println(john)
    fmt.Println(jack)
}