Skip to content

Instantly share code, notes, and snippets.

@gagliardetto
Created June 22, 2018 19:31
Show Gist options
  • Save gagliardetto/c720e1b01a1a1c9689ada38320ec7c5d to your computer and use it in GitHub Desktop.
Save gagliardetto/c720e1b01a1a1c9689ada38320ec7c5d to your computer and use it in GitHub Desktop.
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