diff --git a/structs/go.mod b/structs/go.mod new file mode 100644 index 0000000..f2176ed --- /dev/null +++ b/structs/go.mod @@ -0,0 +1,3 @@ +module structs + +go 1.17 diff --git a/structs/main.go b/structs/main.go new file mode 100644 index 0000000..03ef969 --- /dev/null +++ b/structs/main.go @@ -0,0 +1,35 @@ +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, + }, + } + (&person1).updateName("asd") + person1.print() +} + +func (p *person) updateName(newFirstName string) { + (*p).firstName = newFirstName +} + +func (p person) print() { + fmt.Printf("%+v", p) +}