Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. )
  6.  
  7. type User struct {
  8. Name string
  9. }
  10.  
  11. func (u *User) sayName(speaker string) bool {
  12. fmt.Printf("Hello %s, my name is %s\n", speaker, u.Name)
  13. return true
  14. }
  15.  
  16. type Role interface {
  17. unlockGate() bool
  18. }
  19.  
  20. type Admin struct {
  21. *User
  22. roleType string
  23. SecretPassword string
  24. entries int32
  25. }
  26.  
  27. // A method needed by the Role interface.
  28. func (a *Admin) unlockGate() bool {
  29. a.entries++
  30. fmt.Printf("unlocking gate as %s\n", a.Name)
  31. return true
  32. }
  33.  
  34. // A function that works on any Role.
  35. func unlock(r Role) {
  36. r.unlockGate()
  37. }
  38.  
  39. func main() {
  40.  
  41. b := &Admin{&User{"Pancho"}, "administrator", "pa$$word", 0}
  42. b.sayName("Roberto")
  43.  
  44. b.unlockGate()
  45. unlock(b)
  46.  
  47. fmt.Printf("Total entries %d\n", b.entries)
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement