Skip to content

Instantly share code, notes, and snippets.

@hoenirvili
Created October 18, 2015 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoenirvili/a8ecf04998a2075ea060 to your computer and use it in GitHub Desktop.
Save hoenirvili/a8ecf04998a2075ea060 to your computer and use it in GitHub Desktop.
Example of using interfaces in Go
package main
import (
"log"
)
type Notifier interface {
Notify() error
}
//our User struct
type User struct {
Name string
Email string
}
//basic Handler
func SendNotification(notify Notifier) error {
return notify.Notify()
}
// define our user method to notify us
func (u *User) Notify() error {
log.Printf("User: Sengind User, Mail to %s<%s>\n",
u.Name,
u.Email)
return nil
}
func main() {
user:= &User {
Name: "Alber Jones",
Email: "albJones@email.com",
}
SendNotification(user)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment