Created
August 3, 2011 21:14
-
-
Save blixt/1123791 to your computer and use it in GitHub Desktop.
Gogogogo!
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" | |
type Person struct { | |
name string | |
age int | |
} | |
func (person *Person) Present() { | |
fmt.Println(person.name, "is", person.age, "years old") | |
} | |
type Dog struct { | |
nick string | |
} | |
func (dog *Dog) Present() { | |
fmt.Println(dog.nick, "is a dog") | |
} | |
type presenter interface { | |
Present() | |
} | |
func PrettyPresent(obj presenter) { | |
fmt.Print(".-´¨`-._.-´¨`-._.-´¨`-.\n* ") | |
obj.Present() | |
fmt.Println("`-._.-´¨`-._.-´¨`-._.-´") | |
} | |
func post_do() { | |
if err := recover(); err != nil { | |
fmt.Println("omg!", err) | |
} else { | |
fmt.Println("ok!") | |
} | |
} | |
func do_something() int { | |
defer post_do() | |
a := []int{1, 2, 3} | |
return a[1337] | |
} | |
func main() { | |
andreas := &Person{"Andreas", 24} | |
candy := &Dog{"Candy"} | |
candy.Present() | |
PrettyPresent(candy) | |
andreas.Present() | |
PrettyPresent(andreas) | |
do_something() | |
fmt.Println("lol, j/k") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment