Skip to content

Instantly share code, notes, and snippets.

@dlsniper
Created September 18, 2016 20:58
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 dlsniper/84452f47a19a28f9eec30853a96fb30d to your computer and use it in GitHub Desktop.
Save dlsniper/84452f47a19a28f9eec30853a96fb30d to your computer and use it in GitHub Desktop.
Dependency injection in Go by explicitly passing the dependency
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