Created
February 3, 2014 15:31
-
-
Save alehano/8785933 to your computer and use it in GitHub Desktop.
This file contains 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" | |
) | |
func decorator(f func(s string)) func(s string) { | |
return func(s string) { | |
fmt.Println("Started") | |
f(s) | |
fmt.Println("Done") | |
} | |
} | |
func doSomething(s string) { | |
fmt.Println(s) | |
} | |
func main() { | |
decorator(doSomething)("Do something") | |
} |
awesome,it is a pity that Go
do not support the @decorator
grammar that Python
supports right now. :)
Clear and simple. Thanks!
very simple and very clear,thx!!!
I referred your code! Thanks!
What about method example?
I liked it , thanks a lot for an awesome example !
good example. thanks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fantastic, simple example of decorators in Go, thank you. The only one I have seen that doesn't confuse matters.