Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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")
}
@andyrees

This comment has been minimized.

Copy link

andyrees commented Aug 4, 2015

Fantastic, simple example of decorators in Go, thank you. The only one I have seen that doesn't confuse matters.

@andyxning

This comment has been minimized.

Copy link

andyxning commented Dec 21, 2015

awesome,it is a pity that Go do not support the @decorator grammar that Python supports right now. :)

@pomkine

This comment has been minimized.

Copy link

pomkine commented Jan 13, 2016

Clear and simple. Thanks!

@wuxinwei

This comment has been minimized.

Copy link

wuxinwei commented May 14, 2016

very simple and very clear,thx!!!

@pyohei

This comment has been minimized.

Copy link

pyohei commented Jul 2, 2016

I referred your code! Thanks!

@kirugan

This comment has been minimized.

Copy link

kirugan commented Jul 20, 2016

What about method example?

@skippy123

This comment has been minimized.

Copy link

skippy123 commented Oct 18, 2016

I liked it , thanks a lot for an awesome example !

@chenghung

This comment has been minimized.

Copy link

chenghung commented Jan 23, 2018

good example. thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.