Created
November 13, 2018 05:11
-
-
Save nikita8/94ddb83971ce67a36630217075253303 to your computer and use it in GitHub Desktop.
Private Method in Go
This file contains 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
// Go | |
type User struct { | |
Username string | |
password string | |
} | |
func (u User) GetPassword() string{ | |
return u.secretPassword() | |
} | |
func (u User) secretPassword() string { | |
return u.password | |
} | |
func main(){ | |
user := User{"username", "password"} | |
fmt.Println("username: " + user.Username) | |
fmt.Println("password: " + user.GetPassword()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment