Created
September 18, 2016 20:45
-
-
Save dlsniper/7942b985b3bca1054e0d26641bd014d9 to your computer and use it in GitHub Desktop.
Dependency injection in Go via wrapping the function
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 "log" | |
type printerFunc func(message string, args ...interface{}) | |
func helloWrapper(p printerFunc) func(string, ...interface{}) { | |
return func(message string, arguments ...interface{}) { | |
p(message, arguments...) | |
} | |
} | |
func main() { | |
hello := helloWrapper(log.Printf) | |
hello("hello %s", "world") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fantastic!