learn_go/structs/main.go

36 lines
502 B
Go
Raw Normal View History

2022-02-09 23:15:49 +01:00
package main
import "fmt"
type contactInfo struct {
email string
zipCode int
}
type person struct {
firstName string
lastName string
contactInfo
}
func main() {
person1 := person{
firstName: "Bert",
lastName: "Bertrandt",
contactInfo: contactInfo{
email: "asd@bsd.de",
zipCode: 1234,
},
}
2022-02-12 00:22:02 +01:00
person1.updateName("asd")
2022-02-09 23:15:49 +01:00
person1.print()
}
func (p *person) updateName(newFirstName string) {
(*p).firstName = newFirstName
}
func (p person) print() {
fmt.Printf("%+v", p)
}