From 7a51de11e4f5397efc34635a25e760f16902ac02 Mon Sep 17 00:00:00 2001 From: benjamyn Date: Wed, 29 Sep 2021 09:15:57 +1000 Subject: [PATCH] POINTERS --- structs/go.mod | 3 +++ structs/main.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 structs/go.mod create mode 100644 structs/main.go diff --git a/structs/go.mod b/structs/go.mod new file mode 100644 index 0000000..f9b70b8 --- /dev/null +++ b/structs/go.mod @@ -0,0 +1,3 @@ +module lovelynet.net/structs + +go 1.17 diff --git a/structs/main.go b/structs/main.go new file mode 100644 index 0000000..be58b6f --- /dev/null +++ b/structs/main.go @@ -0,0 +1,36 @@ +package main + +import "fmt" + +type contactInfo struct { + email string + zipCode int +} + +type person struct { + firstName string + lastName string + contactInfo +} + +func main() { + jim := person{ + firstName: "Jim", + lastName: "Party", + contactInfo: contactInfo{ + email: "jim@gmail.com", + zipCode: 3177, + }, + } + + jim.updateName("test") + jim.print() +} + +func (pointerToPerson *person) updateName(name string) { + (*pointerToPerson).firstName = name +} + +func (p person) print() { + fmt.Printf("%+v\n", p) +}