Last active
April 18, 2022 03:57
-
-
Save jerryan999/a300ae89f4261d633191f633452a297d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type User struct { | |
Name string | |
Age int | |
} | |
func (u User) String() string { | |
return fmt.Sprintf("User[Name: %s, Age: %d]", u.Name, u.Age) | |
} | |
// value receiver | |
func (u User) SetAge(age int) { | |
u.Age = age | |
fmt.Println(u) | |
} | |
func main() { | |
u := User{ | |
Name: "John", | |
Age: 25, | |
} | |
u.SetAge(30) | |
fmt.Println(u) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type User struct { | |
Name string | |
Age int | |
} | |
func (u User) String() string { | |
return fmt.Sprintf("User[Name: %s, Age: %d]", u.Name, u.Age) | |
} | |
// value receiver | |
func (u *User) SetAge(age int) { | |
u.Age = age | |
fmt.Println(u) | |
} | |
func main() { | |
u := User{ | |
Name: "John", | |
Age: 25, | |
} | |
u.SetAge(30) | |
fmt.Println(u) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment