Created
September 18, 2016 20:58
-
-
Save dlsniper/84452f47a19a28f9eec30853a96fb30d to your computer and use it in GitHub Desktop.
Dependency injection in Go by explicitly passing the dependency
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 hello(p printerFunc) { | |
p("hello %s", "world") | |
} | |
func main() { | |
hello(log.Printf) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment