I just started learning to go on lectures from meil ru and here were a few questions:
1) How to understand the sa := SecretAgent{Person: Person{"James", "12312321321"}, LicenseToKill: true} , namely Person: Person{"James", "12312321321"} what is this for JS? Full code:
package main import "fmt" type Person struct { Name string inn string } type SecretAgent struct { Person LicenseToKill bool } func (p Person) GetName() string { return p.Name } func main() { sa := SecretAgent{Person: Person{"James", "12312321321"}, LicenseToKill: true} fmt.Println("secret inn", sa.GetName()) } 2) Why, when you implement interface methods, is it crucial to accept the reference to the parent by value, not pointer? T.e. There is a code:
package main type Walk interface { Fly() } type Person struct { Name string } func (p Person) Fly() { println("gg") } func main() { p := Person{"gg"} zz(p) } func zz(f Walk) { b := f.(Person) println(b.Name) } And it works, but it is worth changing func (p Person) to func (p *Person) and everything breaks down when the structure is passed to the function receiving interface. I understand that this is done because the interface does not know anything about the data and therefore cannot change them by pointer. I'm right?