This commit is contained in:
Benjamyn Love 2021-09-29 09:15:57 +10:00
parent 49b436d6f9
commit 7a51de11e4
2 changed files with 39 additions and 0 deletions

3
structs/go.mod Normal file
View File

@ -0,0 +1,3 @@
module lovelynet.net/structs
go 1.17

36
structs/main.go Normal file
View File

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