Created
June 22, 2018 19:31
-
-
Save gagliardetto/c720e1b01a1a1c9689ada38320ec7c5d 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" | |
func main() { | |
user := User{} | |
// Set the group: | |
groupSetter("admin", user) | |
fmt.Println(user) | |
} | |
type User struct { | |
Name string | |
group string | |
} | |
// GetGroup returns the group the user belongs to. | |
func (user *User) GetGroup() string { | |
return user.group | |
} | |
func groupSetter(name string, user UserInterface) error { | |
return user.SetGroup(name) | |
} | |
// | |
type UserInterface interface { | |
GetGroup() string | |
SetGroup(name string) error | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment