13
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

structのclone

Posted at

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 &copy
   }
   
   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"
})

13
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?