Skip to content

Instantly share code, notes, and snippets.

@nikita8
Created November 13, 2018 05:11
Show Gist options
  • Save nikita8/94ddb83971ce67a36630217075253303 to your computer and use it in GitHub Desktop.
Save nikita8/94ddb83971ce67a36630217075253303 to your computer and use it in GitHub Desktop.
Private Method in Go
// 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