structのclone
logging library zapで利用されているのを見つけました
https://github.com/uber-go/zap/blob/master/logger.go#L251-L253
sample
main.go
import "github.com/davecgh/go-spew/spew"
type A struct {
a string
}
func (a *A) clone() *A {
copy := *a
return ©
}
func main() {
org := &A{"hoge"}
clone := org.clone()
spew.Dump(org)
spew.Dump(clone)
}
output
(*main.A)(0xc42000e280)({
a: (string) (len=4) "hoge"
})
(*main.A)(0xc42000e290)({
a: (string) (len=4) "hoge"
})