add structs

This commit is contained in:
Johannes Rothe 2022-02-09 23:15:49 +01:00
parent afbc977e1d
commit 37979af331
2 changed files with 38 additions and 0 deletions

3
structs/go.mod Normal file
View File

@ -0,0 +1,3 @@
module structs
go 1.17

35
structs/main.go Normal file
View File

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