Skip to content

Instantly share code, notes, and snippets.

@jtbonhomme
Last active February 27, 2018 11:27
Show Gist options
  • Save jtbonhomme/0623e002086a2c267abce6453bf0c77d to your computer and use it in GitHub Desktop.
Save jtbonhomme/0623e002086a2c267abce6453bf0c77d to your computer and use it in GitHub Desktop.
Initialize nested struct (https://play.golang.org/p/A7dbuyPGsw0)
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)
}
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)
}
@jtbonhomme
Copy link
Author

jtbonhomme commented Feb 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment