Skip to content

Instantly share code, notes, and snippets.

@alehano
Created February 3, 2014 15:31
Show Gist options
  • Select an option

  • Save alehano/8785933 to your computer and use it in GitHub Desktop.

Select an option

Save alehano/8785933 to your computer and use it in GitHub Desktop.
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

andyrees commented Aug 4, 2015

Copy link
Copy Markdown

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

@andyxning

Copy link
Copy Markdown

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

@pomkine

pomkine commented Jan 13, 2016

Copy link
Copy Markdown

Clear and simple. Thanks!

@wuxinwei

Copy link
Copy Markdown

very simple and very clear,thx!!!

@pyohei

pyohei commented Jul 2, 2016

Copy link
Copy Markdown

I referred your code! Thanks!

@kirugan

kirugan commented Jul 20, 2016

Copy link
Copy Markdown

What about method example?

@skippy123

Copy link
Copy Markdown

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

@chenghung

chenghung commented Jan 23, 2018

Copy link
Copy Markdown

good example. thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment