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) +}