Open atc0005 opened 5 years ago
Snippet:
I'm assuming your Employee struct is now of the form
type Employee struct { Person number int }
If so, as described in Effective Go, "Constructors and composite literals", you can construct structs using { } syntax in two ways:
Providing the values for each (and every) field in order, eg.
dude := Employee{ Person{"Me"}, 1 }
Or, by using field:value initializers for any number of fields in any order, eg.
dude := Employee{ Person:Person{"Me"}, number:1 } or dude := Employee{ number:1, Person:Person{"Me"} } or dude := Employee{ Person:Person{"Me"} } (number gets default value of 0)
But, you can't mix and match those styles, as you've attempted to do.
I ran into this again today while working on atc0005/go-ezproxy#13. I started off trying something like this:
result := TerminateUserSessionResult{
UserSession: {
SessionID: session.SessionID,
},
}
and then other variations before I finally realized this was a valid way to do it:
result := TerminateUserSessionResult{
UserSession: UserSession{
SessionID: session.SessionID,
},
}
That said, https://docs.google.com/document/d/1zDgIzUCDE31AeAbhGUcdTQh-ISdFRcfrnaCdT8F2PDA is very clear about not using multi-part construction (which is what I was doing), so that should be kept in mind.
From atc0005/Learn-Go-in-3-Hours/classwork/ch4/structs/main.go@99b123b3ac8bb42b7ab9787399f37a04d90206f2: