add structs
This commit is contained in:
parent
afbc977e1d
commit
37979af331
3
structs/go.mod
Normal file
3
structs/go.mod
Normal file
@ -0,0 +1,3 @@
|
||||
module structs
|
||||
|
||||
go 1.17
|
35
structs/main.go
Normal file
35
structs/main.go
Normal 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)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user