Last active
July 5, 2017 11:46
-
-
Save inancgumus/8a593bd64b6a1b33239ae5e5b4cb60b0 to your computer and use it in GitHub Desktop.
Golang decorator pattern
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" | |
) | |
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") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Click here to try the code on Go Playground.