Skip to content

Instantly share code, notes, and snippets.

@inancgumus
Last active July 5, 2017 11:46
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 inancgumus/8a593bd64b6a1b33239ae5e5b4cb60b0 to your computer and use it in GitHub Desktop.
Save inancgumus/8a593bd64b6a1b33239ae5e5b4cb60b0 to your computer and use it in GitHub Desktop.
Golang decorator pattern
package main
import (
"fmt"
)
type displayFunc func(s string)
func decorate(f displayFunc) displayFunc {
return func(s string) {
fmt.Println("Before")
f(s)
fmt.Println("After")
}
}
func display(s string) {
fmt.Println(s)
}
func main() {
display := decorate(display)
display("In the middle")
}
@inancgumus
Copy link
Author

inancgumus commented Jul 5, 2017

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