Last active
February 27, 2018 11:27
-
-
Save jtbonhomme/0623e002086a2c267abce6453bf0c77d to your computer and use it in GitHub Desktop.
Initialize nested struct (https://play.golang.org/p/A7dbuyPGsw0)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"fmt" | |
) | |
type Toto struct { | |
S string | |
N struct { | |
I int64 | |
} | |
} | |
func main() { | |
toto := &Toto{ | |
S: "help", | |
N: struct{ | |
I int64 | |
}{ | |
I: 1234, | |
}, | |
} | |
fmt.Printf("Hello, playground: %v\n", toto) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type N struct { | |
I int64 | |
} | |
type Toto struct { | |
S string | |
N | |
} | |
func main() { | |
n := N{1234} | |
toto := &Toto{ | |
S: "help", | |
N: n, | |
} | |
fmt.Printf("Hello, playground: %v\n", toto) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nested2.go: https://play.golang.org/p/V-k_5HlFuLR