Skip to content

Instantly share code, notes, and snippets.

@mrkplt
Created March 22, 2015 13:34
Show Gist options
  • Select an option

  • Save mrkplt/b114d2525a03cfb95acd to your computer and use it in GitHub Desktop.

Select an option

Save mrkplt/b114d2525a03cfb95acd to your computer and use it in GitHub Desktop.

Revisions

  1. mrkplt created this gist Mar 22, 2015.
    50 changes: 50 additions & 0 deletions gistfile1.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    # https://www.youtube.com/watch?v=gRpUfjTwSOo&utm_source=golangweekly&utm_medium=email
    package main

    import "fmt"

    type user struct {
    name string
    email string
    }

    type admin struct {
    user
    level string
    }


    func(u *user) notify() {
    fmt.Printf("Sending email to %s<%s>\n",
    u.name,
    u.email,
    )
    }

    type notifier interface {
    notify()
    }


    func main() {
    foo := user{
    name: "Randolf Gorgeous",
    email: "[email protected]",
    }

    admin := admin{
    user: user{
    name: "mark platt",
    email: "[email protected]",

    },
    level: "super",
    }

    sendNotification(&admin)
    sendNotification(&foo)
    }

    func sendNotification(n notifier) {
    n.notify()
    }