-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (32 loc) · 872 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
)
func main() {
fmt.Println("Methods")
user := User{}
user.Id = 1
user.Name = "John Doe"
user.Email = "[email protected]"
fmt.Println("The user is:", user)
fmt.Printf("The user in detail is: %+v\n", user)
fmt.Println("The user's name is:", user.Name)
anotherUser := User{2, "Jane doe", "[email protected]"}
fmt.Println("The another user's name is:", anotherUser.Name)
anotherUser.SendEmail()
anotherUser.ChangeUserName("Bill Gates")
fmt.Println("Outside change name fn:", user.Name)
/* The name didn't changed on main struct because it was passed by value */
}
type User struct {
Id int
Name string
Email string
}
func (user User) SendEmail() {
fmt.Println("Sending email to:", user.Email)
}
func (user User) ChangeUserName(name string) {
user.Name = name
fmt.Println("Inside change name fn:", user.Name)
}